From d7829fd08b9bb1be64b689c61cb6115c77dc79d0 Mon Sep 17 00:00:00 2001 From: taskylizard <75871323+taskylizard@users.noreply.github.com> Date: Tue, 11 Mar 2025 21:17:17 +0000 Subject: [PATCH] fix: include streaming site star while indexing Fixes #7. --- make_fmhy_bookmarks.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/make_fmhy_bookmarks.py b/make_fmhy_bookmarks.py index 9f46ab1..19854c3 100644 --- a/make_fmhy_bookmarks.py +++ b/make_fmhy_bookmarks.py @@ -1,4 +1,3 @@ - import requests def addPretext(lines, sectionName, baseURL, subURL): @@ -161,8 +160,8 @@ def alternativeWikiIndexing(): # Instead of saving it to a file, save it into a string variable wiki_adapted_md = '\n'.join(alternativeWikiIndexing()) -# Remove from the lines in wiki_adapted_md any line that doesnt contain the character `⭐` -wiki_adapted_starred_only_md = '\n'.join([line for line in wiki_adapted_md.split('\n') if '⭐' in line]) +# Remove from the lines in wiki_adapted_md any line that doesnt contain the character `⭐` or '🌟' +wiki_adapted_starred_only_md = '\n'.join([line for line in wiki_adapted_md.split('\n') if '⭐' or '🌟' in line]) @@ -171,25 +170,25 @@ import re def markdown_to_html_bookmarks(input_md_text, output_file): # Predefined folder name folder_name = "FMHY" - + # Read the input markdown file #with open(input_file, 'r', encoding='utf-8') as f: # markdown_content = f.read() # Instead of reading from a file, read from a string variable markdown_content = input_md_text - + # Regex pattern to extract URLs and titles from markdown url_pattern = re.compile(r'\[([^\]]+)\]\((https?://[^\)]+)\)') # Regex pattern to extract hierarchy levels hierarchy_pattern = re.compile(r'^\{"([^"]+)", "([^"]+)", "([^"]+)"\}') - + # Dictionary to hold bookmarks by hierarchy bookmarks = {} - + # Split the content by lines lines = markdown_content.split('\n') - + # Parse each line for line in lines: # Find hierarchy levels @@ -198,7 +197,7 @@ def markdown_to_html_bookmarks(input_md_text, output_file): continue level1, level2, level3 = hierarchy_match.groups() - + # Initialize nested dictionaries for hierarchy levels if level1 not in bookmarks: bookmarks[level1] = {} @@ -213,11 +212,11 @@ def markdown_to_html_bookmarks(input_md_text, output_file): # If the input_md_text is wiki_adapted_starred_only_md, only add the first match of url_pattern in each line if input_md_text == wiki_adapted_starred_only_md: matches = matches[:1] - + # Extract the description (text after the last match) last_match_end = line.rfind(')') description = line[last_match_end+1:].replace('**', '').strip() if last_match_end != -1 else '' - + # When the description is empty, use as description the lowest hierachy level that is not empty if not description: description = '- ' + (level3 if level3 != '/' else level2 if level2 else level1) @@ -226,7 +225,7 @@ def markdown_to_html_bookmarks(input_md_text, output_file): for title, url in matches: full_title = f"{title} {description}" if description else title bookmarks[level1][level2][level3].append((full_title, url)) - + # Function to generate HTML from nested dictionary def generate_html(bookmarks_dict, indent=1): html = '' @@ -240,7 +239,7 @@ def markdown_to_html_bookmarks(input_md_text, output_file): html += ' ' * (indent + 1) + f'
{full_title}\n' html += ' ' * indent + '

\n' return html - + # HTML structure html_content = ''' @@ -251,13 +250,13 @@ def markdown_to_html_bookmarks(input_md_text, output_file): # Add the main folder html_content += f'

{folder_name}

\n' html_content += '

\n' - + # Add bookmarks to HTML content html_content += generate_html(bookmarks) - + html_content += '

\n' html_content += '

\n' - + # Write the HTML content to the output file with open(output_file, 'w', encoding='utf-8') as f: f.write(html_content)