Forked from jryio/Prepend YAML Front Matter to Markdown Files
Created
July 12, 2023 12:06
-
-
Save abhishek0010/3b4fdcc06fc89055b9494f5124e1940e to your computer and use it in GitHub Desktop.
Adding YAML front matter to markdown files (title)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For each result of find call our script to run on the filename | |
$ find . -name "*.md" -print0 | xargs -0 -I file ./prepend.sh file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given a file path as an argument | |
# 1. get the file name | |
# 2. prepend template string to the top of the source file | |
# 3. resave original source file | |
filepath="$1" | |
file_name=$(basename $filepath) | |
# Getting the file name (title) | |
md='.md' | |
title=${file_name%$md} | |
# Prepend front-matter to files | |
TEMPLATE="--- | |
layout: page | |
title: $title | |
category: gen | |
--- | |
" | |
echo "$TEMPLATE" | cat - "$filepath" > temp && mv temp "$filepath" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment