Skip to content

Instantly share code, notes, and snippets.

@tillmanj
Created February 13, 2025 19:59
Show Gist options
  • Save tillmanj/a07765da659d830285f42bee008b2336 to your computer and use it in GitHub Desktop.
Save tillmanj/a07765da659d830285f42bee008b2336 to your computer and use it in GitHub Desktop.
Strip the current page from a file in Jekyll and return the path. A collection-agnostic page.dir filter

{% assign url = {{page.url}} | split: "/" | reverse | join: "/" | replace_first: "/", "|" | split: "|" | last | split: "/" | reverse | join: "/" | prepend: "/" | append: "/" %}

{{url}}

@tillmanj
Copy link
Author

The Jekyll filter page.dir only applies to posts, so a solution is needed to provide the same functionality for Collections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment