Skip to content

Instantly share code, notes, and snippets.

@ldcc
Last active May 24, 2019 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ldcc/08d6f5dee39c6487c2059c1e75954c2a to your computer and use it in GitHub Desktop.
Save ldcc/08d6f5dee39c6487c2059c1e75954c2a to your computer and use it in GitHub Desktop.
Jekyll Posts Filename on Liquid.

Get filenames from my present blog posts on jekyll.

Get from single post

1.Split and pick the filename from the post of full path:

{% assign file = page.path | split: "/" | last %}

The page.path which respected the filepath that jekyll does generated.

2.Split the prefix of date, 8(number) + 3(hyphen) = 11(symbol):

{% assign pre = file | slice: 0,11 %}

or

{% assign pre = file | truncate: 11,"" %}

3.Drop that rests:

{% assign fn = file | remove: pre | remove: ".md" %}

For step1 to step3 may simplify:

{% assign fn = page.path | slice: $(a tuple)$ | remove: ".md" %}

Tuple that is a number pair:

(prefix-len + 11),(a number large than filename-len)

Get from folder

The _posts directory tree seems like this:

_posts
|-- xxxx-xx-xx-xxxx.md
|-- ...
|-- xxxx
| |-- xxxx-xx-xx-xxx1.md
| |-- xxxx-xx-xx-xxx2.md
| |-- ...
|-- ...

All posts from subfolder xxxx/ must referal the same filename to handle with, and easy:

{% assign fn = page.path | remove: "_posts/" | split: "/" | first %}

Usage

For now, type {{fn}} to uses that name:

![liquid markup]({{res}}/{{fn}}/my-picture.xxx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment