Permalinks are the output path for your pages, posts. They allow you to structure the directories of your source code different from the directories in your output.
For this project:
Permalinks are like URL shortcuts to longer, crappier URLs. You can define permalinks when creating or editing your posts. (Pages don't need permalinks as you can put them wherever you like already and manually create any extra symlinks you need).
How to:
GitHub Pages (at least) seems to support symlinks, so let's use those.
Allow easy adding of custom permalinks:
when creating a post:
ask user to add permalink: permalink: custom-dir/custom-name
create relative symlink from $permalink to posts/$date/$slugname.html
when re-building a post:
get the permalink as $permalink, from current posts meta info
find all symlinks to current post (old permalinks), delete them
create relative symlink from $permalink to posts/$date/$slugname.html
# Create a symbolic link to a file or directory:
ln -s path/to/file_or_directory path/to/symlink
# Overwrite an existing symbolic to point to a different file:
ln -sf path/to/new_file path/to/symlink
So, something like:
# Function to be called from `create_page.sh`, where $post_date,
# $post_url, $post_slug, etc, are already available:
function create_permalink {
permalink="$1"
# get post info for $2 (if given)
if [ -f "${2//.html/.mdsh}" ];then
get_post_info "${2//.html/.mdsh}"
fi
# delete symlinks to $post
find -L . -xtype l -samefile posts/$post_date/$post_slug.html -delete
# create permalink
mkdir -p $(dirname $permalink)
ln -s "$permalink" "posts/$post_date/$post_slug.html"
# update robots.txt: make search engines ignore full URL,
# and crawl/list only the permalink
echo "Disallow: posts/$post_date/$post_slug.html" >> robots.txt
sort -u robots.txt | uniq > cleaned-robots.txt
mv cleaned-robots.txt robots.txt
}
Background
Form Jekyll site:
For this project:
How to:
GitHub Pages (at least) seems to support symlinks, so let's use those.
Allow easy adding of custom permalinks:
permalink: custom-dir/custom-name
$permalink
toposts/$date/$slugname.html
$permalink
, from current posts meta info$permalink
toposts/$date/$slugname.html
See: https://jekyllrb.com/docs/permalinks/
Also see
ln
usage:So, something like:
Usage:
NOTE:
Also write a
rm_permalink
function which removes the symlink AND the relevant entry from robots.txt!