Skip to content

Commit

Permalink
Improved script tools.
Browse files Browse the repository at this point in the history
- Allows posts to be placed in subdirectories (barryclark#41, barryclark#87).
- Identify posts file with the suffix ‘.markdown’.

**Page creator**
- Pass the posts without any categories or tags.
- Omit the YAML comments for categories/tags.

**Lastmod**
- compatible with one-digit month or day post files.
  • Loading branch information
cotes2020 committed Jul 14, 2020
1 parent 733bb0f commit 5b0aaa5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 56 deletions.
102 changes: 52 additions & 50 deletions _scripts/sh/create_pages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ read_categories() {
local _category=$(echo "$_yaml" | grep "^category:")

if [[ ! -z "$_categories" ]]; then
echo "$_categories" | sed "s/categories: *//;s/\[//;s/\]//;s/, */,/g;s/\"//g;s/'//g"
echo "$_categories" | sed "s/categories: *//;s/\[//;s/\].*//;s/, */,/g;s/\"//g;s/'//g"
elif [[ ! -z "_category" ]]; then
echo "$_category" | sed "s/category: *//;s/\[//;s/\]//;s/, */,/g;s/\"//g;s/'//g"
echo "$_category" | sed "s/category: *//;s/\[//;s/\].*//;s/, */,/g;s/\"//g;s/'//g"
fi
}


read_tags() {
local _yaml=$(_read_yaml $1)
echo "$_yaml" | grep "^tags:" | sed "s/tags: *//;s/\[//;s/\]//;s/, */,/g;s/\"//g;s/'//g"
echo "$_yaml" | grep "^tags:" | sed "s/tags: *//;s/\[//;s/\].*//;s/, */,/g;s/\"//g;s/'//g"
}


Expand All @@ -63,34 +63,38 @@ init() {


create_category() {
local _name=$1
local _filepath="categories/$(echo $_name | sed 's/ /-/g' | awk '{print tolower($0)}').html"

if [[ ! -f $_filepath ]]; then
echo "---" > $_filepath
echo "layout: category" >> $_filepath
echo "title: $_name" >> $_filepath
echo "category: $_name" >> $_filepath
echo "---" >> $_filepath

((category_count=category_count+1))
if [[ ! -z $1 ]]; then
local _name=$1
local _filepath="categories/$(echo $_name | sed 's/ /-/g' | awk '{print tolower($0)}').html"

if [[ ! -f $_filepath ]]; then
echo "---" > $_filepath
echo "layout: category" >> $_filepath
echo "title: $_name" >> $_filepath
echo "category: $_name" >> $_filepath
echo "---" >> $_filepath

((category_count=category_count+1))
fi
fi
}


create_tag() {
local _name=$1
local _filepath="tags/$( echo $_name | sed "s/ /-/g;s/'//g" | awk '{print tolower($0)}' ).html"
if [[ ! -z $1 ]]; then
local _name=$1
local _filepath="tags/$( echo $_name | sed "s/ /-/g;s/'//g" | awk '{print tolower($0)}' ).html"

if [[ ! -f $_filepath ]]; then
if [[ ! -f $_filepath ]]; then

echo "---" > $_filepath
echo "layout: tag" >> $_filepath
echo "title: $_name" >> $_filepath
echo "tag: $_name" >> $_filepath
echo "---" >> $_filepath
echo "---" > $_filepath
echo "layout: tag" >> $_filepath
echo "title: $_name" >> $_filepath
echo "tag: $_name" >> $_filepath
echo "---" >> $_filepath

((tag_count=tag_count+1))
((tag_count=tag_count+1))
fi
fi
}

Expand All @@ -102,47 +106,45 @@ create_tag() {
# $2 - type specified option
#########################################
create_pages() {
if [[ $1 == '' ]]; then
exit 0
fi
if [[ ! -z $1 ]]; then
# split string to array
IFS_BAK=$IFS
IFS=','
local _string=$1

# split string to array
IFS_BAK=$IFS
IFS=','
local _string=$1
case $2 in

case $2 in
$TYPE_CATEGORY)
for i in ${_string#,}; do
create_category $i
done
;;

$TYPE_CATEGORY)
for i in ${_string#,}; do
create_category $i
done
;;
$TYPE_TAG)
for i in ${_string#,}; do
create_tag $i
done
;;

$TYPE_TAG)
for i in ${_string#,}; do
create_tag $i
done
;;
*)
;;

*)
;;
esac

esac
IFS=$IFS_BAK
fi

IFS=$IFS_BAK
}
}


main() {

init

for _file in $(ls "_posts")
for _file in $(find "_posts" -type f \( -iname \*.md -o -iname \*.markdown \))
do
local _path="_posts/$_file"
local _categories=$(read_categories "$_path")
local _tags=$(read_tags "$_path")
local _categories=$(read_categories "$_file")
local _tags=$(read_tags "$_file")

create_pages "$_categories" $TYPE_CATEGORY
create_pages "$_tags" $TYPE_TAG
Expand Down
10 changes: 4 additions & 6 deletions _scripts/sh/dump_lastmod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,12 @@ main() {

local _count=0

for _file in $(ls -r "$POST_DIR")
for _file in $(find ${POST_DIR} -type f \( -iname \*.md -o -iname \*.markdown \))
do
_filepath="$POST_DIR/$_file"
_filename="${_file%.*}" # jekyll cannot read the extension of a file, so omit it.
_filename=${_filename:11} # remove the date
_filename=$(basename $_file | sed 's/[0-9]\([0-9]*-\)//g;s/\..*//' ) # remove date and extension

if _has_changed "$_filepath"; then
_dump "$_filename" "$_filepath"
if _has_changed "$_file"; then
_dump "$_filename" "$_file"
((_count=_count+1))
fi

Expand Down

0 comments on commit 5b0aaa5

Please sign in to comment.