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:

  1. It automatically generates/resolves permalinks for new files
  2. These permalinks don’t include trailing slashes
  3. 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:

  1. Make permalink generation optional via config
  2. Ensure generated permalinks always have trailing slashes
  3. 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 the generate_permalink function
  • src/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

#AI #AITools #BasicMemory