Jekyll Markdown "link" and "post_url" error

Hi.
This link and post_url problems seem not resolved by myself, after a week of struggling, I post this here.

My jekyll is v.4.2.0, so I did as below:

---
layout: default
---
# Blog Post
* [Prologue]({% link Prologue.md %})

# Journey Codes
* [Data Structure (DS)]({% link _posts/Data-Structure/2020-12-12-about.md %})
* [C Language (C)]()
* [Discrete Mathematics (M)]()

[back]({% link index.md %})

Then receive error message:

$ bundle exec jekyll build
Configuration file: C:/Users/user/Desktop/Jwmc999.github.io/_config.yml
            Source: C:/Users/user/Desktop/Jwmc999.github.io
       Destination: C:/Users/user/Desktop/Jwmc999.github.io/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
       Jekyll Feed: Generating feed for posts
  Liquid Exception: Could not find document '_posts/Data-Structure/2020-12-12-about.md' in tag 'link'. Make sure the document exists and the path is correct. in post.md
                    ------------------------------------------------
      Jekyll 4.2.0   Please append `--trace` to the `build` command
                     for any additional information or backtrace.
                    ------------------------------------------------
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/tags/link.rb:32:in `render': Could not find document '_posts/Data-Structure/2020-12-12-about.md' in tag 'link'. (ArgumentError)

Make sure the document exists and the path is correct.
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/liquid-4.0.3/lib/liquid/block_body.rb:103:in `render_node_to_output'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/liquid-4.0.3/lib/liquid/block_body.rb:91:in `render'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/liquid-4.0.3/lib/liquid/template.rb:208:in `block in render'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/liquid-4.0.3/lib/liquid/template.rb:242:in `with_profiling'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/liquid-4.0.3/lib/liquid/template.rb:207:in `render'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/liquid-4.0.3/lib/liquid/template.rb:220:in `render!'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/liquid_renderer/file.rb:39:in `block (3 levels) in render!'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/liquid_renderer/file.rb:59:in `measure_counts'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/liquid_renderer/file.rb:38:in `block (2 levels) in render!'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/liquid_renderer/file.rb:63:in `measure_bytes'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/liquid_renderer/file.rb:37:in `block in render!'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/liquid_renderer/file.rb:70:in `measure_time'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/liquid_renderer/file.rb:36:in `render!'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/renderer.rb:131:in `render_liquid'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/renderer.rb:80:in `render_document'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/renderer.rb:63:in `run'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/site.rb:547:in `render_regenerated'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/site.rb:539:in `block in render_pages'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/site.rb:538:in `each'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/site.rb:538:in `render_pages'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/site.rb:211:in `render'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/site.rb:80:in `process'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:28:in `process_site'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/commands/build.rb:65:in `build'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/commands/build.rb:36:in `process'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `block in process_with_graceful_fail'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `each'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `process_with_graceful_fail'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/commands/build.rb:18:in `block (2 levels) in init_with_program'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `block in execute'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `each'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `execute'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mercenary-0.4.0/lib/mercenary/program.rb:44:in `go'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mercenary-0.4.0/lib/mercenary.rb:21:in `program'
        from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/exe/jekyll:15:in `<top (required)>'
        from C:/Ruby27-x64/bin/jekyll:23:in `load'
        from C:/Ruby27-x64/bin/jekyll:23:in `<main>'

Links to ‘Prologue.md’, ‘index.md’, and ‘post.md’ work, and those three locate in root. The thing is, when I try to link to files under subdirectories, link and 'post_url` do not work. However, if I put the same files on root, they work.
I am looking for a way to avoid moving all posts to root…

I googled link-tag errors on Jekyll v4.0 but didn’t really make changes.

Any insight on how can I fix it?

In case, my repo is GitHub - Jwmc999/Jwmc999.github.io.

Thank you.

Your link tag to the about post matches the path on github exactly so I don’t know what is wrong with that.

What if you use this? I don’t know if the tag supports sub directories

{% post_url Data-Structure/2020-12-12-about %}

Without .md I think.

I haven’t used post_url but I use link tag a lot with subpaths

Given path

foo/bar.md

You can do link tag with the exact path

{% link foo/bar.md %}

Note that the path given to link must always be relative to the repo root - not a relative path like ./bar.md within folder foo.

1 Like

You have collections_dir : . in your config file.
Remove that and the tags will work properly.

2 Likes

Thanks million!!! It works!!!
Thank you very muchhhhhhh! :star_struck: