-
Notifications
You must be signed in to change notification settings - Fork 171
add creation-date-key modification-date-key configuration options
#531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BennoLossin
wants to merge
8
commits into
zk-org:main
Choose a base branch
from
BennoLossin:frontmatter-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+243
−10
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f7b9157
add `creation-date-key` modification-date-key` configuration options
BennoLossin 9de18f6
Update internal/core/config.go
tjex 83ab0cd
Update internal/core/config.go
tjex 038f08b
improve docs
BennoLossin 1128a64
addd link to configuration
BennoLossin 65b97a5
fix git commit hook script
BennoLossin 9410d69
remove useless tests
BennoLossin 667aebe
wip: add tesh case for note custom modification date
tjex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,4 +14,5 @@ Tips | |
| future-proof | ||
| static-sites | ||
| style | ||
| modification-date | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # Modification Dates | ||
|
|
||
| When synchronizing notes across devices or using version control, the file's | ||
| modification time may not reflect when you actually last edited the note. Other | ||
| external tools also might be touching the file while not changing the contents. | ||
| `zk` offers custom [Date Keys](../notes/note-frontmatter.md#date-keys) to allow | ||
| overriding the modification date in the frontmatter of notes. | ||
|
|
||
| ## Configuration | ||
|
|
||
| First, configure `zk` to use the `changed` frontmatter key to obtain the | ||
| modification date in `.zk/config.toml`: | ||
|
|
||
| ```toml | ||
| [format.markdown.frontmatter] | ||
| modification-date-key = "changed" | ||
| ``` | ||
|
|
||
| See the configuration of [Date Keys](../notes/note-frontmatter.md#date-keys) | ||
| for more information. | ||
|
|
||
| Then update your notes' frontmatter to include the key with a date value: | ||
|
|
||
| ```markdown | ||
| --- | ||
| changed: 2025-12-29 09:48 | ||
| --- | ||
| ``` | ||
|
|
||
| ## Automatically Updating Dates | ||
|
|
||
| Since manually changing the modification date is tedious, external tools can be | ||
| automated to automatically update the date in the `changed` key of the | ||
| frontmatter. | ||
|
|
||
| ### Neovim with Autocommands | ||
|
|
||
| Add this to your Neovim configuration to update the `changed` field | ||
| whenever you save a Markdown file: | ||
|
|
||
| ```lua | ||
| vim.api.nvim_create_autocmd("BufWritePre", { | ||
| pattern = "*.md", | ||
| callback = function(args) | ||
| local lines = vim.api.nvim_buf_get_lines(args.buf, 0, -1, false) | ||
| local in_frontmatter = false | ||
|
|
||
| for i, line in ipairs(lines) do | ||
| if line:match("^%-%-%-$") then | ||
| if not in_frontmatter then | ||
| in_frontmatter = true | ||
| else | ||
| break | ||
| end | ||
| elseif in_frontmatter and line:match("^changed:%s") then | ||
| local new_line = "changed: " .. os.date("%Y-%m-%d %H:%M") | ||
| vim.api.nvim_buf_set_lines(args.buf, i - 1, i, false, { new_line }) | ||
| return | ||
| end | ||
| end | ||
| end, | ||
| }) | ||
| ``` | ||
|
|
||
| ### Git Pre-commit Hook | ||
|
|
||
| Create a Git pre-commit hook to automatically update modification dates before committing. | ||
| Save this as `.git/hooks/pre-commit` in your notebook repository: | ||
|
|
||
| ```sh | ||
| #!/usr/bin/env sh | ||
|
|
||
| git diff --cached --name-status | egrep -i "^(A|M).*\.(md)$" | while read a file; do | ||
| sed --in-place "/---.*/,/---.*/s/^changed: [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\}$/changed: $(date "+%Y-%m-%d %H:%M")/" $file | ||
| git add $file | ||
| done | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [note] | ||
| default-title = "Untitled" | ||
| filename = "{{slug title}}" | ||
| template = "default.md" | ||
|
|
||
| [format.markdown.frontmatter] | ||
| modification-date-key = "changed" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| title: {{title}} | ||
| changed: | ||
| --- | ||
|
|
||
| {{content}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| title: Custom Changed Date | ||
| changed: 2026-01-01 19:00 | ||
| --- | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| title: No Changed Date | ||
| changed: | ||
| --- | ||
|
|
||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.