serhii.net

In the middle of the desert you can say anything you want

05 Jun 2024

And back to exporting obsidian to hugo

Obyde needs 3.8 and fails otherwise, new OS maybe time for new ways to convert. There are many actually. Some active mantained and expandable.

For later:

So

obsidian-to-hugo doesn’t support assets/images :( Leaving only ukautz/obsidian-meets-hugo: Command line tool to export Obsidian Vault into Hugo published website for me.

  • preserves Obsidian directory structure — nice
  • not recursive by default
  • doesn’t create _index.md files, and converts existing ones in Obsidian to -index.md
  • doesn’t support folders, but one can filter by tags — good that I used both since the beginning!
    • for multiple tags a “list” is possible — and apparently that’s -i tag1 -i tag2 -i tag31

Current CLI:

go run cmds/omh/main.go --obsidian-root=../public_obs/ -R --hugo-root=../dtb/ --sub-path= -i=uni -i=zc/it -i=zc/rl

Onwards

  • 3 refs not found
  • cyrillic names now unsupported?
    • 220407-2246 Чебуреки etc.
    • damn.
    • It’s the same
      var insane = regexp.MustCompile(`[^a-zA-Z0-9\-]`)
      func Sanitize(in string) string {
      	return insane.ReplaceAllString(in, "")
      }
      
    • w/ chatGPT, changed regex to [^a-zA-Z0-9\-\p{Cyrillic}] — now it does upper+lowercase cyrillics — so now it’s 220407-2246-Чебуреки.md in the md filename, but the URI has it lowercased.
    • Relevant: disablePathToLower in config2 — not changing because cool URIs don’t change and this was the default for years on this website
  • Images are broken
    • ![2024-05-13-182935_1304x442_scrot.png](//assets/2024-05-13-182935-1304-x-442-scrot.png)
    • //assets alrighty…
    • Docu: Static files | Hugo
      • By default, the static/ directory in the site project is used for all static files (e.g. stylesheets, JavaScript, images). The static files are served on the site root path (eg. if you have the file static/image.png you can access it using http://{server-url}/image.png, to include it in a document you can use ![Example image](/image.png)).

      • you can have multiple such directories
    • Ah — maybe it’ll work when uploaded to my website, where /xxx will refer to the website and not my local install
    • If I manually fix //assets/.. to /assets (one slash) then it shows up nicely locally
    • In omh.go this happens: return fmt.Sprintf("[%s](/%s/%s)", title, c.SubPath, target)
    • AH it’s because of my empty subpath directory argument — if I pass something then everything works. Oh GodDAMN it.
    • OK this fixes it. And I hope creates no more problems.
      if c.SubPath == "" {
          return fmt.Sprintf("[%s](%s/%s)", title, c.SubPath, target)
        } else {
      return fmt.Sprintf("[%s](/%s/%s)", title, c.SubPath, target)
      
    } ```
  • Debugging a notes called _index I realize that it takes Hugo frontmatter title from note title, which in turn is the filename, NOT the obsidian file frontmatter title :(
    • problem because my layouts rely on a magic constant in some directories…
    • I hope it’s my last fix.
  // Keep title in Obsidian front-matter as note title if it's there (a la obyde), 
  // otherwise use Obsidian filename for this (standard behaviour). 
  oldTitle := hugo["title"]
  if oldTitle==nil {
    log.Warn("No title in front-matter, using filename in ", note.Title)
    // must have title
    hugo["title"] = note.Title
  } else {
    log.Warn("Using frontmatter title for ", oldTitle)
  }
Nel mezzo del deserto posso dire tutto quello che voglio.