Skip to content

Commit 2a6dd48

Browse files
feat: apply permalink to cli and assets manager
1 parent 13b1df5 commit 2a6dd48

13 files changed

Lines changed: 730 additions & 153 deletions

File tree

docs/about/changelog.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
date: 2025-11-05 10:53:00
2+
date: 2026-01-10 22:35:00
33
title: Changelog
44
permalink:
55
publish: true
@@ -12,6 +12,16 @@ 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.1.0 - 2026-01-10
16+
17+
### Changed
18+
19+
- [Commands Line Interface](../usage/cli.md) and [Asset manager](../usage/asset-manager.md) now use permalink to determine asset directory, instead of filename.
20+
21+
- Keep forward compatibility if can't identify permalink from note file.
22+
23+
- Affacted CLI commands: `new`, `remove`, `move`. For users, only notice that `new` command now requires a permalink argument.
24+
1525
## 3.0.2 - 2025-11-05
1626

1727
### Fixed

docs/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
date: 2025-11-04 23:45:00
2+
date: 2026-01-10 22:04:00
33
title: Getting Started
44
permalink:
55
publish: true
@@ -34,7 +34,7 @@ The most highlighted feature of the plugin is the CLI commands to manage notes,
3434

3535
To create a note, you can use the following command:
3636
```bash
37-
mkdocs-note new /path/to/note
37+
mkdocs-note new my-permalink /path/to/note
3838
```
3939

4040
It will create a note in the specified path and create a corresponding asset directory in the `assets` directory which will be co-located with the note.

docs/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
---
2-
date: 2025-10-15 00:57:12
2+
date: 2026-01-10 22:10:12
33
title: Welcome
44
permalink:
55
publish: true
66
---
77

88
# Welcome
99

10+
!!! tip "Notice"
11+
`v3.1.0` is now avaliable, the release now make some changes in [Commands Line Interface](usage/cli.md), See [Changelog](about/changelog.md#310---2026-01-10) for more details.
12+
1013
## Mkdocs Note
1114

1215
**MkDocs Note** is a plugin for MkDocs that automatically manages documentations in your mkdocs-based sites. It's designed to create a unified note-taking and documentation experience.

docs/usage/cli.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
date: 2025-11-05 20:30:00
2+
date: 2026-01-10 22:09:00
33
title: Command Line Interface
44
permalink:
55
publish: true
@@ -60,13 +60,10 @@ Create a new note file with proper asset structure.
6060

6161
```bash
6262
# Create a simple note
63-
mkdocs-note new docs/notes/my-note.md
63+
mkdocs-note new my-permalink docs/notes/my-note.md
6464
6565
# Create a note in nested directory
66-
mkdocs-note new docs/notes/python/intro.md
67-
68-
# Using template (feature planned)
69-
mkdocs-note new docs/notes/article.md --template templates/article.md
66+
mkdocs-note new python-intro docs/notes/python/intro.md
7067
```
7168

7269
- **Output:**
@@ -76,7 +73,8 @@ Create a new note file with proper asset structure.
7673
```
7774
✅ Successfully created note
7875
📝 Note: docs/notes/my-note.md
79-
📁 Assets: docs/notes/assets/my-note/
76+
🔗 Permalink: my-permalink
77+
📁 Assets: docs/notes/assets/my-permalink/
8078
```
8179
8280
### `remove`

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.2"
3+
version = "3.1.0"
44
description = "A MkDocs plugin to add note boxes to your documentation."
55
readme = "README.md"
66
requires-python = ">=3.12"

src/mkdocs_note/cli.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,23 +127,21 @@ def cli(ctx):
127127

128128

129129
@cli.command("new")
130+
@click.argument("permalink", required=True)
130131
@click.argument("file_path", required=True)
131-
@click.option(
132-
"--template",
133-
"-t",
134-
type=click.Path(exists=True, path_type=Path),
135-
help="Custom template file to use",
136-
)
137132
@click.pass_context
138-
def new_command(ctx, file_path, template):
133+
def new_command(ctx, permalink, file_path):
139134
"""Create a new note file with proper asset structure.
140135
141136
\b
142137
Examples:
143-
mkdocs-note new docs/notes/my-note.md
144-
mkdocs-note new docs/notes/python/intro.md
138+
mkdocs-note new my-permalink docs/notes/my-note.md
139+
mkdocs-note new python-intro docs/notes/python/intro.md
145140
146-
FILE_PATH: Path where the new note file should be created
141+
\b
142+
Arguments:
143+
PERMALINK: The permalink value for frontmatter and asset directory name
144+
FILE_PATH: Path where the new note file should be created
147145
"""
148146
try:
149147
# Load configuration and setup environment
@@ -153,22 +151,30 @@ def new_command(ctx, file_path, template):
153151
# Convert to Path
154152
note_path = Path(file_path)
155153

154+
# Validate permalink
155+
if not permalink or not permalink.strip():
156+
click.echo("❌ Error: Permalink cannot be empty", err=True)
157+
sys.exit(1)
158+
159+
permalink = permalink.strip()
160+
156161
# Check if file already exists
157162
if note_path.exists():
158163
click.echo(f"❌ Error: File already exists: {note_path}", err=True)
159164
sys.exit(1)
160165

161166
# Create the note using NewCommand
162167
command = NewCommand()
163-
command.execute(note_path)
168+
command.execute(permalink, note_path)
164169

165-
# Get asset directory path
166-
asset_dir = cli_common.get_asset_directory(note_path)
170+
# Get asset directory path based on permalink
171+
asset_dir = cli_common.get_asset_directory_by_permalink(note_path, permalink)
167172

168173
# Check if creation was successful
169174
if note_path.exists():
170175
click.echo("✅ Successfully created note")
171176
click.echo(f"📝 Note: {note_path}")
177+
click.echo(f"🔗 Permalink: {permalink}")
172178
click.echo(f"📁 Assets: {asset_dir}")
173179
sys.exit(0)
174180
else:
@@ -220,8 +226,15 @@ def remove_command(ctx, file_path, keep_assets, yes):
220226
click.echo(f"❌ Error: File does not exist: {note_path}", err=True)
221227
sys.exit(1)
222228

223-
# Get asset directory before removal
224-
asset_dir = cli_common.get_asset_directory(note_path)
229+
# Get asset directory before removal (based on permalink if available)
230+
permalink = cli_common.get_permalink_from_file(note_path)
231+
if permalink:
232+
asset_dir = cli_common.get_asset_directory_by_permalink(
233+
note_path, permalink
234+
)
235+
else:
236+
# Fallback to filename-based for backwards compatibility
237+
asset_dir = cli_common.get_asset_directory(note_path)
225238
asset_exists = asset_dir.exists()
226239

227240
# Confirmation prompt (unless --yes)
@@ -238,9 +251,11 @@ def remove_command(ctx, file_path, keep_assets, yes):
238251
# Check if removal was successful
239252
if not note_path.exists():
240253
click.echo(f"✅ Successfully removed note: {note_path}")
254+
if permalink:
255+
click.echo(f"🔗 Permalink: {permalink}")
241256
if not keep_assets and asset_exists:
242257
click.echo(f"📁 Removed assets: {asset_dir}")
243-
else:
258+
elif keep_assets:
244259
click.echo(f"📁 Kept assets: {asset_dir}")
245260
sys.exit(0)
246261
else:
@@ -420,7 +435,7 @@ def clean_command(ctx, dry_run, yes):
420435
sys.exit(0)
421436

422437
# Actually clean
423-
click.echo("\n🗑️ Removing orphaned assets...")
438+
click.echo("\n🗑️ Removing orphaned assets...")
424439
command.execute(dry_run=False)
425440

426441
click.echo(

0 commit comments

Comments
 (0)