9

It's pretty basic stuff, I guess but I couldn't figure out how to do it.

What I want to do is very simple.

By using Jekyll plugin system, I want to extend Liquid tag to return filename of post.

{{% page.filename %}}

will parse to something like

jekyll-plugin.markdown
Léo Léopold Hertz 준영
  • 119,377
  • 159
  • 417
  • 655
studiomohawk
  • 380
  • 1
  • 3
  • 12

2 Answers2

3

Well, it's not exactly the method you're looking for, but you could just include the filename in the yaml headers for the file. It's probably a bad choice for files that you'll move around and tweak, but since there don't appear to be a wealth of answers pouring forth, maybe it's good enough.

OldTroll
  • 751
  • 6
  • 20
1

I think I got it. Here I´m checking if a file has a line that contains "Filename:". If not, it places it on the second line, with the variable of the filename.

#!/bin/bash
for file in $(ls *.md)
do
if grep -Fq "filename: " $file
then
   # code if not found
   echo "File: $file already processed"
else
    # code if found
    echo "Adding the line on file: $file"
    awk -v n=2 -v s="filename: $file" 'NR == n {print s} {print}' $file > tmp.txt
    mv tmp.txt $file
fi

done

brunosan
  • 285
  • 2
  • 5
  • 16