Files
LifeFaq/app/services/__pycache__/markdown_processor.cpython-312.pyc

50 lines
5.0 KiB
Plaintext
Raw Normal View History

2024-12-12 19:58:26 +01:00
<EFBFBD>
2024-12-29 04:34:25 +01:00
<00><>pg<70><00><00>T<00>ddlZddlmZddlmZddlmZddlmZm Z Gd<06>d<07>Z
y)<08>N)<01> BeautifulSoup)<01>FastAPI)<01>MarkdownRenderer)<02> Environment<6E>FileSystemLoaderc<00>P<00>eZdZdZddededefd<06>Zdedefd <09>Zded
ed efd <0C>Z d <0A>Z
y)<0F>MarkdownProcessorz<72>
2024-12-12 19:58:26 +01:00
A class to process Markdown files, extract metadata, and generate a single
'index.html' per category directory using a custom rendering engine.
2024-12-29 04:34:25 +01:00
N<> input_dir<69> templates_dir<69>appc<00>T<00>||_tt|<02><00><01>|_||_y)z<>
2024-12-12 19:58:26 +01:00
Initialize the MarkdownProcessor.
Args:
input_dir (str): Root directory containing category subdirectories.
templates_dir (str): Directory containing Jinja2 templates.
2024-12-29 04:34:25 +01:00
)<01>loaderN)r
rr<00>envr )<04>selfr
r r s <20>F/home/hjess/PycharmProjects/LifeFaq/app/services/markdown_processor.py<70>__init__zMarkdownProcessor.__init__s$<00><00>#<23><04><0E><1E>&6<>}<7D>&E<>F<><04><08><16><04><08><00>directory_path<74>returnc
<00><00>ddlm}g}ttj|<01><00>D]<5D>}|j d<03>s<01>tj j||<04>}t|dd<05><06>5}|j<00>}ddd<07>t||j<00><08>}|j<07>\} }
|j|
jd d
<EFBFBD>| |
jd d <0C>|
jd d<0E>d<0F><04><00><>|S#1swY<00>~xYw)a
2024-12-12 19:58:26 +01:00
Process all Markdown files in a directory using Markdown and Jinja2 custom tags.
Args:
directory_path (str): Path to the category directory.
Returns:
list: A list of processed sections containing metadata and rendered content.
2024-12-29 04:34:25 +01:00
r)<01>Pathz.md<6D>r<>utf-8<><01>encodingN)<02> file_pathr <00>title<6C>Untitled<65>summary<72><00>author<6F>Unknown)<04>name<6D>contentrr!)<0F>pathlibr<00>sorted<65>os<6F>listdir<69>endswith<74>path<74>join<69>open<65>readrr <00>render_markdown_with_jinja<6A>append<6E>get) rrr<00>sections<6E>filer<00>md_file<6C>markdown_content<6E>markdown_render<65>rendered_content<6E>metadatas r<00>$_process_markdown_files_in_directoryz6MarkdownProcessor._process_markdown_files_in_directorys<><00><00> !<21><15><08><1B>2<EFBFBD>:<3A>:<3A>n<EFBFBD>5<>6<>D<EFBFBD><13>}<7D>}<7D>U<EFBFBD>#<23><1E>G<EFBFBD>G<EFBFBD>L<EFBFBD>L<EFBFBD><1E><14>><3E> <09><19>)<29>S<EFBFBD>7<EFBFBD>;<3B>w<EFBFBD>'.<2E>|<7C>|<7C>~<7E>$<24><<3C>"2<>Y<EFBFBD>4<EFBFBD>8<EFBFBD>8<EFBFBD>"T<><0F>.=<3D>-W<>-W<>Zj<5A>-l<>*<2A> <20>(<28><19><0F><0F>$<24>L<EFBFBD>L<EFBFBD><17>*<2A>=<3D>/<2F>'<27>|<7C>|<7C>I<EFBFBD>r<EFBFBD>:<3A>&<26>l<EFBFBD>l<EFBFBD>8<EFBFBD>Y<EFBFBD>?<3F> !<12><13>7<>$<18><0F><<3C>;<3B>s <00>*C8<05>8D r1<00> output_filec<00><><00>|jjd<01>}|jtjj |<01>j <00>|<02><02>}tj|d<03><04>t|dd<06><07>5}t|d<08>}|jd <09>
2024-12-21 02:16:29 +01:00
<EFBFBD>}|j|<08>d d d <0B>td |<03><00><02>y #1swY<00>xYw) a?
2024-12-12 19:58:26 +01:00
Generate the index.html file for a category using the combined sections.
Args:
directory_path (str): Path to the category directory.
sections (list): List of processed Markdown content and metadata.
output_file (str): Path to save the generated index.html.
2024-12-29 04:34:25 +01:00
zcombined_template.html)rr1T)<01>exist_ok<6F>wrrz html.parser<65>html5)<01> formatterNz Generated: ) r<00> get_template<74>renderr'r*<00>basename<6D>
capitalize<EFBFBD>makedirsr,r<00>prettify<66>write<74>print) rrr1r9<00>template<74> rendered_html<6D>output<75>soup<75> cleaned_htmls r<00>_generate_index_htmlz&MarkdownProcessor._generate_index_html?s<><00><00><18>8<EFBFBD>8<EFBFBD>(<28>(<28>)A<>B<><08> <20><0F><0F><14>'<27>'<27>"<22>"<22>><3E>2<>=<3D>=<3D>?<3F><1D>(<28>
2024-12-21 02:16:29 +01:00
<EFBFBD> <0A> <0B> <0B> <0B>N<EFBFBD>T<EFBFBD>2<> <11>+<2B>s<EFBFBD>W<EFBFBD> 5<><16> <20>-<2D><1D>@<40>D<EFBFBD><1F>=<3D>=<3D>7<EFBFBD>=<3D>;<3B>L<EFBFBD> <12>L<EFBFBD>L<EFBFBD><1C> &<26>6<> <0E> <0B>K<EFBFBD>=<3D>)<29>*<2A> 6<> 5<>s <00>?0C<03>Cc<00>0<00>tj|j<00>D]t\}}}|D]i}tjj ||<04>}tjj |d<01>}|j |<05>}|s<01>W|j |||<06><00>k<00>vy)zV
2024-12-12 19:58:26 +01:00
Run the Markdown processing workflow: one 'index.html' per category.
z
2024-12-29 04:34:25 +01:00
index.htmlN)r'<00>walkr
r*r+r8rL)r<00>root<6F>dirs<72>_<> directory<72> category_pathr9r1s r<00>runzMarkdownProcessor.runWsz<00><00> <20>W<EFBFBD>W<EFBFBD>T<EFBFBD>^<5E>^<5E>4<>M<EFBFBD>D<EFBFBD>$<24><01>!<21> <09> "<22><07><07> <0C> <0C>T<EFBFBD>9<EFBFBD> =<3D> <0A> <20>g<EFBFBD>g<EFBFBD>l<EFBFBD>l<EFBFBD>=<3D>,<2C>G<> <0B> <20>D<>D<>]<5D>S<><08><1B><18>-<2D>-<2D>m<EFBFBD>X<EFBFBD>{<7B>S<>"<22>5r)N) <0B>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__<5F>strrr<00>listr8rLrT<00>rrr r sV<00><00><08>
<17>#<23>
<17>c<EFBFBD>
<17>g<EFBFBD>
<17>"<18>3<EFBFBD>"<18>4<EFBFBD>"<18>H+<2B>3<EFBFBD>+<2B>$<24>+<2B>UX<55>+<2B>0 Trr ) r'<00>bs4r<00>fastapir<00>app.services.markdown_renderr<00>jinja2rrr r[rr<00><module>r`s"<00><01> <09><1D><1B>9<>0<>[T<01>[Tr