Skip to content

Commit

Permalink
option to ignore obsidian metadata file to run the theme without obsi…
Browse files Browse the repository at this point in the history
…dian index

Signed-off-by: lucasew <lucas59356@gmail.com>
  • Loading branch information
lucasew committed Sep 4, 2021
1 parent edf67d8 commit ef1d774
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 51 deletions.
24 changes: 13 additions & 11 deletions layouts/partials/backlinks.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{{ $root := . }}
{{ with .Page.File }}
{{ $index := getJSON "./content/meta.json" }}
{{ $obsPage := $root.Page.File.Path | replaceRE ".md$" "" }}
{{ with index $index $obsPage }}
{{ $refs := .referencedBy }}
{{ if gt (len $refs) 0 }}
<h1>Me referenciando</h1>
{{ range sort .referencedBy }}
{{ $page := site.GetPage . }}
{{ partialCached "page-link.html" $page $page.Permalink }}
{{ if not .Site.Params.disableObsidian }}
{{ $root := . }}
{{ with .Page.File }}
{{ $index := getJSON "./content/meta.json" }}
{{ $obsPage := $root.Page.File.Path | replaceRE ".md$" "" }}
{{ with index $index $obsPage }}
{{ $refs := .referencedBy }}
{{ if gt (len $refs) 0 }}
<h1>Me referenciando</h1>
{{ range sort .referencedBy }}
{{ $page := site.GetPage . }}
{{ partialCached "page-link.html" $page $page.Permalink }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
Expand Down
82 changes: 42 additions & 40 deletions layouts/partials/content.html
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
{{ $index := getJSON "./content/meta.json" }}
{{ $page := .Page }}
{{ $content := .Content }}
{{ if not .Site.Params.disableObsidian }}
{{ $index := getJSON "./content/meta.json" }}
{{ $page := .Page }}
{{ $content := .Content }}

{{ $content = replaceRE `(?s)<pre><code class="language-ad-([a-z]*)[^>]*>title:([^\n]*)\n(.+?)<\/code><\/pre>` (partial "admonition.html" (dict "body" (safeHTML "<markdownme>$3</markdownme>") "type" "$1" "title" "$2")) $content }}
{{ $content = replaceRE `(?s)<pre><code class="language-ad-([a-z]*)[^>]*>title:([^\n]*)\n(.+?)<\/code><\/pre>` (partial "admonition.html" (dict "body" (safeHTML "<markdownme>$3</markdownme>") "type" "$1" "title" "$2")) $content }}

{{ $extraBlocks := findRE "(?s)<markdownme>.+?</markdownme>" $content }}
{{ range $extraBlocks }}
{{ $body := replaceRE "(?s)<markdownme>(.+?)</markdownme>" "$1" . }}
{{ $content = replace $content . ($body | markdownify) 1 }}
{{ end }}

{{ $links := findRE "\\!\\[\\[([^\\]]*)\\]\\]" $content}}
{{ range $links }}
{{ $wikilink := . }}
{{ $wikilinkName := . | replaceRE "\\!\\[\\[(.*)\\]\\]" "$1" | replaceRE "\\..*$" "" }}
{{ $path := $wikilinkName }}
{{ if (isset $index $wikilinkName) }}
{{ $meta := index $index $wikilinkName }}
{{ $path = $meta.path }}
{{ $extraBlocks := findRE "(?s)<markdownme>.+?</markdownme>" $content }}
{{ range $extraBlocks }}
{{ $body := replaceRE "(?s)<markdownme>(.+?)</markdownme>" "$1" . }}
{{ $content = replace $content . ($body | markdownify) 1 }}
{{ end }}
{{ $path := $path | replaceRE "^([^/])" "/$1" }}
{{ $linkPlaceholder := "<img src=\"$path\"></img>" }}
{{ $link := replace $linkPlaceholder "$path" $path }}
{{ $content = replace $content $wikilink $link }}
{{ end }}

{{ $links := findRE "\\[\\[([^\\]]*)\\]\\]" $content}}
{{ range $links }}
{{ $wikilink := . }}
{{ $wikilinkName := . | replaceRE "\\[\\[(.*)\\]\\]" "$1" }}
{{ $path := $wikilinkName }}
{{ $path = strings.TrimSuffix "_index.md" $path }}
{{ if (isset $index $wikilinkName) }}
{{ $path = (index $index $wikilinkName).path }}
{{ else }}
{{ $path = printf "%s.md" $wikilinkName }}
{{ end }}
{{ $path := $path | replaceRE "^([^/])" "/$1" }}
{{ with site.GetPage $path }}
{{ $link := partialCached "page-link.html" . .Permalink | string }}
{{ $link = trim $link "\n" | safeHTML }}
{{ $links := findRE "\\!\\[\\[([^\\]]*)\\]\\]" $content}}
{{ range $links }}
{{ $wikilink := . }}
{{ $wikilinkName := . | replaceRE "\\!\\[\\[(.*)\\]\\]" "$1" | replaceRE "\\..*$" "" }}
{{ $path := $wikilinkName }}
{{ if (isset $index $wikilinkName) }}
{{ $meta := index $index $wikilinkName }}
{{ $path = $meta.path }}
{{ end }}
{{ $path := $path | replaceRE "^([^/])" "/$1" }}
{{ $linkPlaceholder := "<img src=\"$path\"></img>" }}
{{ $link := replace $linkPlaceholder "$path" $path }}
{{ $content = replace $content $wikilink $link }}
{{ end }}
{{ end }}

{{ $content | safeHTML }}
{{ $links := findRE "\\[\\[([^\\]]*)\\]\\]" $content}}
{{ range $links }}
{{ $wikilink := . }}
{{ $wikilinkName := . | replaceRE "\\[\\[(.*)\\]\\]" "$1" }}
{{ $path := $wikilinkName }}
{{ $path = strings.TrimSuffix "_index.md" $path }}
{{ if (isset $index $wikilinkName) }}
{{ $path = (index $index $wikilinkName).path }}
{{ else }}
{{ $path = printf "%s.md" $wikilinkName }}
{{ end }}
{{ $path := $path | replaceRE "^([^/])" "/$1" }}
{{ with site.GetPage $path }}
{{ $link := partialCached "page-link.html" . .Permalink | string }}
{{ $link = trim $link "\n" | safeHTML }}
{{ $content = replace $content $wikilink $link }}
{{ end }}
{{ end }}

{{ $content | safeHTML }}
{{ end }}

0 comments on commit ef1d774

Please sign in to comment.