Fix basic-memory permalink generation for Jekyll compatibility
The basic-memory tool automatically generates permalinks in note frontmatter (YAML) without trailing slashes, which causes Jekyll to create flat files instead of directory/index.html structures.
Current Problem
When basic-memory syncs files:
- It automatically generates/resolves permalinks for new files
- These permalinks don’t include trailing slashes
- Jekyll interprets frontmatter permalinks without trailing slashes as requests for flat files (
permalink.html
) rather than directory structures (permalink/index.html
)
Current Workaround
I’ve added code to my post-update
git hook script that removes permalink lines from all notes before building the site:
puts "Removing 'permalink:' from frontmatter in _notes..."
notes_path = File.join(release_path, "_notes")
if Dir.exist?(notes_path)
Dir.glob(File.join(notes_path, "**/*.md")).each do |note_file|
content = File.read(note_file)
# Use regex to find frontmatter block and remove the permalink line within it
# Uses multiline mode (m) and captures content before/after the permalink line
modified_content = content.sub(/^(---\s*\n.*?)permalink:.*\n(.*?^---\s*$\n)/m) do |match|
"#{$1}#{$2}" # Reconstruct without the permalink line
end
# Write back only if content was changed
if modified_content != content
File.write(note_file, modified_content)
puts "Removed permalink from: #{note_file.gsub(release_path + '/', '')}"
end
end
else
puts "Warning: _notes directory not found at #{notes_path}, skipping permalink removal."
end
Goals for a Proper Fix
Create a patch for basic-memory to fix this by implementing one or more of:
- Make permalink generation optional via config
- Ensure generated permalinks always have trailing slashes
- Allow configuring a custom frontmatter key instead of “permalink”
Implementation Notes
Ideal implementation would add new config option(s) like:
permalink_generation: "disabled" | "with_trailing_slash" | "as_is"
permalink_key: "custom_key_name"
Look at these files in the basic-memory codebase:
src/basic_memory/utils.py
- Contains thegenerate_permalink
functionsrc/basic_memory/sync/sync_service.py
- Handles permalink generation during sync
Jekyll Behavior
Jekyll’s handling of permalinks:
- With trailing slash (
permalink: /my-url/
): Creates directory structure (/my-url/index.html
) - Without trailing slash (
permalink: /my-url
): Creates flat file (/my-url.html
) - Collection default in
_config.yml
(permalink: /:title/
): Uses trailing slash for directory structure