Can I have a template function for the original post's path?

I am currently working on a simple PHP script for static comments for a planned Hugo installation, that basically works as follows:

  • Submit the post’s RelPermalink as the post_id.
  • Write the comment into a YAML file under Permalink/comments/.
  • Run Hugo.
  • The rendered page in /public contains the new comment.

Simple (and already working), in theory. In practice, RelPermalink is not necessarily the same thing as the actual permalink. I basically need an easy(ish) way to HTTP POST a post’s source’s path back.

Example: posts with a new title, posts which will be published a month later, … all of those have a RelPermalink that’s not identical with the source folder, so my script will fail. What I would need is a way to have OrigPermalink or something in my partial template, so a post stored under content/posts/2024/10/foo/index.md can have a template variable that contains [posts/]2024/10/foo or something, regardless of what title or date is set in the front matter.

Any ideas?

I think of these two that could help:

  • Page methods - Path

    since v0.123.0 this returns a logical Path for the page object (dunno how stable that is). read the page to get an impression

  • Page methods - File

    returns the File information if the Page is backed by a file. shoulkd be true for your use case. You may then call any of the methods described on the page to get details.

1 Like

This seems to be exactly what I needed. Thank you!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.