22
33import os
44import json
5- from pathlib import Path
65
76from mkdocs .structure .files import Files , File
87from mkdocs .config .defaults import MkDocsConfig
@@ -150,20 +149,15 @@ def on_page_markdown(
150149 Returns:
151150 str: The markdown content.
152151 """
153- if self .config .recent_notes_config ["enabled" ]:
154- if self .is_note_index_page (page .file ):
155- markdown = insert_recent_note_links (
156- markdown = markdown ,
157- notes_list = self .notes_list ,
158- insert_num = self .config .recent_notes_config ["insert_num" ],
159- replace_marker = self .config .recent_notes_config ["insert_marker" ],
160- )
161- else :
162- log .warning ("Recent notes are not supported on non-note index pages." )
163- markdown = markdown
164- else :
165- log .debug ("Recent notes insertion are disabled." )
166- markdown = markdown
152+ # 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 ):
154+ markdown = insert_recent_note_links (
155+ markdown = markdown ,
156+ notes_list = self .notes_list ,
157+ insert_num = self .config .recent_notes_config ["insert_num" ],
158+ replace_marker = self .config .recent_notes_config ["insert_marker" ],
159+ )
160+ log .debug (f"Recent notes inserted into { page .file .src_uri } " )
167161
168162 return markdown
169163
@@ -172,12 +166,14 @@ def is_note_index_page(self, f: File) -> bool:
172166 """Check if the page is a note index page.
173167
174168 Args:
175- page (Page ): The page to check.
169+ f (File ): The file to check.
176170
177171 Returns:
178172 bool: True if the page is a note index page, False otherwise.
179173 """
180- return f .src_uri == str (Path (self .config .notes_root ) / "index.md" )
174+ # src_uri is relative to docs_dir, so we just check for 'index.md'
175+ # when notes_root is the docs_dir itself
176+ return f .src_uri == "index.md"
181177
182178
183179def insert_recent_note_links (
@@ -198,9 +194,13 @@ def insert_recent_note_links(
198194 str: The markdown content with recent note links inserted.
199195 """
200196
201- content = ""
197+ content = "<ul> \n "
202198 for f in notes_list [:insert_num ]:
203199 title = extract_title (f )
204200 date = extract_date (f ).strftime ("%Y-%m-%d %H:%M:%S" )
205- content += f"- <div class='recent-notes'><a href='{ f .page .abs_url } '>{ title } </a><small>{ date } </small></div>\n "
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 "
206206 return markdown .replace (replace_marker , content )
0 commit comments