Skip to content

Commit 9bdfd45

Browse files
Merge pull request #62 from virtualguard101/dev
fix: fix 2 issue in plugin module
2 parents 6d5f2c7 + 8e84b9e commit 9bdfd45

9 files changed

Lines changed: 90 additions & 31 deletions

File tree

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
include LICENSE
22
include README.md
3-
recursive-include src/mkdocs_note/utils/graphps/static *
3+
recursive-include src/mkdocs_note/static *

docs/about/changelog.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
date: 2025-11-05 00:20:00
2+
date: 2025-11-05 10:53:00
33
title: Changelog
44
permalink:
55
publish: true
@@ -12,6 +12,14 @@ All notable changes to this project will be documented in this file.
1212
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
1313
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1414

15+
## 3.0.1 - 2025-11-05
16+
17+
### Fixed
18+
19+
- Fixed issue where [recent notes](../usage/recent-notes.md) were not inserted into index page if notes_root was not default value (`docs`).
20+
21+
- Fixed issue that cannot copy static assets to output directory which can make the [graph visualization](../usage/network-graph.md) not working.
22+
1523
## 3.0.0 - 2025-11-04 (Architecture Simplification)
1624

1725
### Changed

docs/contributing/contributing.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
date: 2025-10-15 01:06:51
2+
date: 2025-11-05 11:00:00
33
title: Contributing
44
permalink:
55
publish: true
@@ -54,13 +54,7 @@ To get started with local development, follow these steps:
5454
5555
4. **Run Tests**
5656
57-
To make sure everything is set up correctly, run the test suite:
58-
59-
```bash
60-
./tests/test.sh
61-
```
62-
63-
Or use `pytest` directly:
57+
To make sure everything is set up correctly, use `pytest` run the test suite:
6458
6559
```bash
6660
uv run pytest

docs/references/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
date: 2025-10-16 14:25:41
3-
title: Index
3+
title: API References
44
permalink:
5-
publish: true
5+
publish: false
66
---
77

8-
# Index
8+
# API References
99

1010
Start writing your note content...

docs/usage/installation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ Then you can run the tests for installation verification:
5959
```bash
6060
uv run pytest
6161
```
62+
63+
More details about development setup, please refer to [Contributing](../contributing/contributing.md#Development-Setup).

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "mkdocs-note"
3-
version = "3.0.0"
3+
version = "3.0.1"
44
description = "A MkDocs plugin to add note boxes to your documentation."
55
readme = "README.md"
66
requires-python = ">=3.12"

src/mkdocs_note/plugin.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,27 @@ def is_note_index_page(self, f: File) -> bool:
172172
Returns:
173173
bool: True if the page is a note index page, False otherwise.
174174
"""
175-
# src_uri is relative to docs_dir, so we just check for 'index.md'
176-
# when notes_root is the docs_dir itself
177-
return f.src_uri == "index.md"
175+
from pathlib import Path
176+
177+
# Check if file ends with index.md
178+
if not f.src_uri.endswith("index.md"):
179+
return False
180+
181+
# Check if file is the index.md directly under notes_root
182+
try:
183+
notes_dir = (
184+
Path(self.config.notes_root)
185+
if isinstance(self.config.notes_root, str)
186+
else self.config.notes_root
187+
)
188+
file_path = Path(f.abs_src_path)
189+
# Get the relative path from notes_root to the file
190+
rel_path = file_path.relative_to(notes_dir)
191+
# If the relative path is exactly "index.md", it's the index page
192+
return str(rel_path) == "index.md"
193+
except (ValueError, AttributeError):
194+
# File is not within notes_root
195+
return False
178196

179197

180198
def insert_recent_note_links(
@@ -204,4 +222,5 @@ def insert_recent_note_links(
204222
# No indentation to avoid Markdown treating it as code block
205223
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'
206224
content += "</ul>\n"
225+
log.info(f"Insert {insert_num} recent notes into index page")
207226
return markdown.replace(replace_marker, content)

tests/test_plugin.py

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,55 @@ def test_config_default_values(self):
4141

4242
def test_is_note_index_page(self):
4343
"""Test is_note_index_page method."""
44-
# Create a mock file
45-
mock_file = Mock()
46-
# src_uri is relative to docs_dir, so 'index.md' not 'docs/index.md'
47-
mock_file.src_uri = "index.md"
48-
49-
# Test with default notes_root
50-
result = self.plugin.is_note_index_page(mock_file)
51-
self.assertTrue(result)
52-
53-
# Test with non-index file
54-
mock_file.src_uri = "some-other-page.md"
55-
result = self.plugin.is_note_index_page(mock_file)
56-
self.assertFalse(result)
44+
import tempfile
45+
import os
46+
47+
# Create a temporary directory structure
48+
with tempfile.TemporaryDirectory() as temp_dir:
49+
# Create notes_root directory
50+
notes_root = os.path.join(temp_dir, "docs")
51+
os.makedirs(notes_root, exist_ok=True)
52+
53+
# Create index.md in notes_root
54+
index_file = os.path.join(notes_root, "index.md")
55+
with open(index_file, "w") as f:
56+
f.write("# Index")
57+
58+
# Create a non-index file
59+
other_file = os.path.join(notes_root, "some-other-page.md")
60+
with open(other_file, "w") as f:
61+
f.write("# Other Page")
62+
63+
# Create a subdirectory with its own index.md
64+
sub_dir = os.path.join(notes_root, "subdir")
65+
os.makedirs(sub_dir, exist_ok=True)
66+
sub_index_file = os.path.join(sub_dir, "index.md")
67+
with open(sub_index_file, "w") as f:
68+
f.write("# Sub Index")
69+
70+
# Set notes_root in config
71+
self.plugin.config.notes_root = notes_root
72+
73+
# Test 1: index.md directly under notes_root should return True
74+
mock_file = Mock()
75+
mock_file.src_uri = "index.md"
76+
mock_file.abs_src_path = index_file
77+
result = self.plugin.is_note_index_page(mock_file)
78+
self.assertTrue(result, "index.md directly under notes_root should be True")
79+
80+
# Test 2: non-index file should return False
81+
mock_file = Mock()
82+
mock_file.src_uri = "some-other-page.md"
83+
mock_file.abs_src_path = other_file
84+
result = self.plugin.is_note_index_page(mock_file)
85+
self.assertFalse(result, "Non-index file should be False")
86+
87+
# Test 3: index.md in subdirectory should return False
88+
mock_file = Mock()
89+
mock_file.src_uri = "subdir/index.md"
90+
mock_file.abs_src_path = sub_index_file
91+
result = self.plugin.is_note_index_page(mock_file)
92+
self.assertFalse(result, "index.md in subdirectory should be False")
5793

5894
def test_on_files(self):
5995
"""Test on_files event handler."""

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)