1212from mkdocs_note .config import MkdocsNoteConfig
1313from mkdocs_note .utils import scanner
1414from mkdocs_note .utils .meta import extract_title , extract_date
15- from mkdocs_note .graph import Graph , add_static_resouces , inject_graph_script , copy_static_assets
15+ from mkdocs_note .graph import (
16+ Graph ,
17+ add_static_resouces ,
18+ inject_graph_script ,
19+ copy_static_assets ,
20+ )
1621
1722
1823log = get_plugin_logger (__name__ )
1924
25+
2026class MkdocsNotePlugin (BasePlugin [MkdocsNoteConfig ]):
2127 """Mkdocs Note Plugin entry point."""
2228
2329 notes_list : list [File ] = []
24-
2530
2631 @event_priority (100 )
2732 def on_files (self , files : Files , config : MkDocsConfig ) -> Files :
@@ -46,12 +51,7 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig:
4651
4752 return config
4853
49- def on_pre_build (
50- self ,
51- * ,
52- config : dict ,
53- ** kwagrs
54- ) -> None :
54+ def on_pre_build (self , * , config : dict , ** kwagrs ) -> None :
5555 """Handle pre-build."""
5656 if self .config .graph_config ["enabled" ]:
5757 self ._graph = Graph (self .config .graph_config )
@@ -121,7 +121,7 @@ def on_post_build(
121121 config (MkDocsConfig): The MkDocs configuration.
122122 """
123123 # Build graph if enabled
124- if hasattr (self , ' _graph' ) and hasattr (self , ' _files' ):
124+ if hasattr (self , " _graph" ) and hasattr (self , " _files" ):
125125 self ._graph (self ._files )
126126 self ._write_graph_file (config = config )
127127
@@ -150,7 +150,9 @@ def on_page_markdown(
150150 str: The markdown content.
151151 """
152152 # Only process recent notes on the note index page
153- if self .config .recent_notes_config ["enabled" ] and self .is_note_index_page (page .file ):
153+ if self .config .recent_notes_config ["enabled" ] and self .is_note_index_page (
154+ page .file
155+ ):
154156 markdown = insert_recent_note_links (
155157 markdown = markdown ,
156158 notes_list = self .notes_list ,
@@ -161,7 +163,6 @@ def on_page_markdown(
161163
162164 return markdown
163165
164-
165166 def is_note_index_page (self , f : File ) -> bool :
166167 """Check if the page is a note index page.
167168
@@ -177,30 +178,30 @@ def is_note_index_page(self, f: File) -> bool:
177178
178179
179180def insert_recent_note_links (
180- markdown : str ,
181- notes_list : list [File ],
182- insert_num : int ,
183- replace_marker : str ,
181+ markdown : str ,
182+ notes_list : list [File ],
183+ insert_num : int ,
184+ replace_marker : str ,
184185) -> str :
185- """Insert recent note links into the markdown.
186-
187- Args:
188- markdown (str): The markdown content.
189- notes_list (list[File]): The list of valid notes.
190- insert_num (int): The number of recent notes to insert.
191- replace_marker (str): The marker to replace.
192-
193- Returns:
194- str: The markdown content with recent note links inserted.
195- """
196-
197- content = "<ul>\n "
198- for f in notes_list [:insert_num ]:
199- title = extract_title (f )
200- date = extract_date (f ).strftime ("%Y-%m-%d %H:%M:%S" )
201- # Use f.url (relative URL) or f.page.url if page is available
202- url = f .page .url if hasattr (f , ' page' ) and f .page else f .url
203- # No indentation to avoid Markdown treating it as code block
204- content += f'<li><div style="display:flex; justify-content:space-between; align-items:center;"><a href="{ url } ">{ title } </a><span style="font-size:0.8em; color:#888;">{ date } </span></div></li>\n '
205- content += "</ul>\n "
206- return markdown .replace (replace_marker , content )
186+ """Insert recent note links into the markdown.
187+
188+ Args:
189+ markdown (str): The markdown content.
190+ notes_list (list[File]): The list of valid notes.
191+ insert_num (int): The number of recent notes to insert.
192+ replace_marker (str): The marker to replace.
193+
194+ Returns:
195+ str: The markdown content with recent note links inserted.
196+ """
197+
198+ content = "<ul>\n "
199+ for f in notes_list [:insert_num ]:
200+ title = extract_title (f )
201+ date = extract_date (f ).strftime ("%Y-%m-%d %H:%M:%S" )
202+ # Use f.url (relative URL) or f.page.url if page is available
203+ url = f .page .url if hasattr (f , " page" ) and f .page else f .url
204+ # No indentation to avoid Markdown treating it as code block
205+ content += f'<li><div style="display:flex; justify-content:space-between; align-items:center;"><a href="{ url } ">{ title } </a><span style="font-size:0.8em; color:#888;">{ date } </span></div></li>\n '
206+ content += "</ul>\n "
207+ return markdown .replace (replace_marker , content )
0 commit comments