HUGO

Quartz urls spaces hyphens relative path problem. Replace not working on index

{{$src := "test%20test"}}
{{$src = replace $src "%20" "-"}}
this works as expected: It results in $src being equal to “test-test”
{{$src := index . "source"}}
{{$src = replace $src "%20" "-"}}
this does not work as expected: It results in $src being equal to “test%20test” (Assuming index . "source" is equal to “test%20test”). What gives?

1 Like

I’m unable to reproduce your problem.

{{ with dict "source" "test%20test" }}
  {{ $src := index . "source" }}
  {{ $src = replace $src "%20" "-" }}
  {{ $src }} --> test-test 
{{ end }}

Maybe the context (the dot) isn’t what you think it is?
Or perhaps you are looking at the value in the wrong scope?

Does it matter what the context is if index . "source" renders as test%20test regardless of replace?

In my case, <a href="{{index . "source"}}"></a> produces a link with an href of “…/test%20test”. thus, index . "source" equals “…/test%20test”. So using replace should replace the %20 with a hyphen, regardless of the context, right?

Regarding scope: Here is my code:

    {{- range $inbound -}}
        {{$src := index . "source"}}
        {{$src = replace $src "%20" "-"}}
        <li>
            <a href="{{$src | safeHTML}}">link</a>
        </li>
    {{- end -}}

The scope is correct, right?

The scope is fine. I suspect inbound is not what you think it is.

{{ $inbound := slice (dict "source" "test%20test") }}
{{ range $inbound }}
  {{ $src := index . "source" }}
  {{ $src = replace $src "%20" "-" }}
  {{ $src }} --> test-test
{{ end }}

I don’t understand why it matters what inbound is. I know that index . "source" produces test%20test. Isn’t that enough? Why go up a layer of abstraction? Why look at the entire contents of the dictionary if I already have the value of the only element I care about? Sorry for being thick

You are showing us pieces of your code and asking us to guess. I have no idea.

If you use my example it works as expected. You are doing or starting with something different.

Can you share your repository?

Sorry. Here it is: quartz/backlinks.html at hugo · bur3ku/quartz · GitHub

git clone --recurse-submodules https://github.com/bur3ku/quartz
cd quartz/
hugo

ERROR 2021/10/21 18:08:51 render of “page” failed: execute of template failed: template: _default/single.html:21:6: executing “_default/single.html” at <partial “footer.html” .>: error calling partial: execute of template failed: template: partials/footer.html:4:10: executing “partials/footer.html” at <partial “backlinks.html” .>: error calling partial: “/home/jmooring/temp/quartz/layouts/partials/backlinks.html:8:18”: execute of template failed: template: partials/backlinks.html:8:18: executing “partials/backlinks.html” at <index $.Site.Data.linkIndex.index.backlinks $curPage>: error calling index: index of untyped nil

data
├── config.yaml
└── graphConfig.yaml

Where is linkIndex ?

I can’t build it locally either. It uses github pages workflow. Committing automatically builds and deploys to github pages. I don’t know how it works :confused:

Yeah, so that bit is kind of important.

I test it via bur3ku.github.io/quartz/disjunction, it deploys there

If it needs to be tested to be solved then I guess we’re stuck… should I delete the issue?

EDIT: I can’t reply because I reached max replies as new user.

ok so I need to figure out how to do this: quartz/deploy.yaml at hugo · bur3ku/quartz · GitHub locally. Any idea how?

EDIT: Woah that worked! So you can see that hyphenated links are working in the body (via using replace in layouts/_default/single.html), but the backlinks are not working despite using replace in layouts/partials/backlinks.html

I think you should figure out how to build the site locally, then worry about deployment.

From the root of your project directory:

hugo mod init github.com/bur3ku/quartz
go get github.com/jackyzha0/hugo-obsidian
hugo-obsidian -input=content -output=data
hugo

What is the URL of a page where the backlinks aren’t working? Also, I bumped your user level—hopefully you can reply instead of editing earlier posts. You might have to logout/login.

I just pushed a commit that updates backlinks.html to show the problem. http://localhost:1313/quartz/disjunction/. The /token instance backlink goes to /token instance instead of /token-instance.
It’s also live here: https://bur3ku.github.io/quartz/disjunction/

Insert this just after {{range $inbound }}

<pre>
  {{ jsonify (dict "indent" "  ") . }}
</pre>

Like I said…

I suspect inbound is not what you think it is.

Ooooh I get it. You’re a good teacher. Thank you! Working on a regex solution…

You’re welcome. I think all of this could have been avoided by using kebab-case for your file names:

my-stoopid-file-name.md

instead of

My Stoopid File Name.md

Just saying…

yes, but the titles of the pages are tethered to the file names, and I don’t want kebab-case titles