mirror of
https://github.com/cotes2020/jekyll-theme-chirpy.git
synced 2025-12-18 21:53:26 +00:00
Pretty shell format.
This commit is contained in:
@@ -18,32 +18,28 @@ TYPE_TAG=1
|
||||
category_count=0
|
||||
tag_count=0
|
||||
|
||||
|
||||
_read_yaml() {
|
||||
local _endline="$(grep -n "\-\-\-" "$1" | cut -d: -f 1 | sed -n '2p')"
|
||||
head -"$_endline" "$1"
|
||||
}
|
||||
|
||||
|
||||
read_categories() {
|
||||
local _yaml="$(_read_yaml "$1")"
|
||||
local _categories="$(echo "$_yaml" | grep "^categories *:")"
|
||||
local _category="$(echo "$_yaml" | grep "^category *:")"
|
||||
|
||||
if [[ ! -z "$_categories" ]]; then
|
||||
if [[ -n $_categories ]]; then
|
||||
echo "$_categories" | sed "s/categories *: *//;s/\[//;s/\].*//;s/, */,/g;s/\"//g;s/'//g"
|
||||
elif [[ ! -z "_category" ]]; then
|
||||
elif [[ -n "_category" ]]; then
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
init() {
|
||||
|
||||
if [[ -d categories ]]; then
|
||||
@@ -61,31 +57,29 @@ init() {
|
||||
mkdir categories tags
|
||||
}
|
||||
|
||||
|
||||
create_category() {
|
||||
if [[ ! -z $1 ]]; then
|
||||
if [[ -n $1 ]]; then
|
||||
local _name=$1
|
||||
local _filepath="categories/$(echo "$_name" | sed 's/ /-/g' | awk '{print tolower($0)}').html"
|
||||
|
||||
if [[ ! -f "$_filepath" ]]; then
|
||||
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))
|
||||
((category_count = category_count + 1))
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
create_tag() {
|
||||
if [[ ! -z $1 ]]; then
|
||||
if [[ -n $1 ]]; then
|
||||
local _name=$1
|
||||
local _filepath="tags/$( echo "$_name" | sed "s/ /-/g;s/'//g" | awk '{print tolower($0)}' ).html"
|
||||
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"
|
||||
@@ -93,12 +87,11 @@ create_tag() {
|
||||
echo "tag: $_name" >> "$_filepath"
|
||||
echo "---" >> "$_filepath"
|
||||
|
||||
((tag_count=tag_count+1))
|
||||
((tag_count = tag_count + 1))
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
#########################################
|
||||
# Create HTML pages for Categories/Tags.
|
||||
# Arguments:
|
||||
@@ -106,7 +99,7 @@ create_tag() {
|
||||
# $2 - type specified option
|
||||
#########################################
|
||||
create_pages() {
|
||||
if [[ ! -z $1 ]]; then
|
||||
if [[ -n $1 ]]; then
|
||||
# split string to array
|
||||
IFS_BAK=$IFS
|
||||
IFS=','
|
||||
@@ -126,23 +119,20 @@ create_pages() {
|
||||
done
|
||||
;;
|
||||
|
||||
*)
|
||||
;;
|
||||
*) ;;
|
||||
|
||||
esac
|
||||
esac
|
||||
|
||||
IFS=$IFS_BAK
|
||||
IFS=$IFS_BAK
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
|
||||
init
|
||||
|
||||
for _file in $(find "_posts" -type f \( -iname \*.md -o -iname \*.markdown \))
|
||||
do
|
||||
for _file in $(find "_posts" -type f \( -iname \*.md -o -iname \*.markdown \)); do
|
||||
local _categories=$(read_categories "$_file")
|
||||
local _tags=$(read_tags "$_file")
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ POST_DIR=_posts
|
||||
OUTPUT_DIR=_data
|
||||
OUTPUT_FILE=updates.yml
|
||||
|
||||
|
||||
_init() {
|
||||
|
||||
if [[ ! -d "$OUTPUT_DIR" ]]; then
|
||||
@@ -33,7 +32,6 @@ _init() {
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
_has_changed() {
|
||||
local _log_count="$(git log --pretty=%ad "$1" | wc -l | sed 's/ *//')"
|
||||
_log_count=$((_log_count + 0))
|
||||
@@ -45,7 +43,6 @@ _has_changed() {
|
||||
return 1 # false
|
||||
}
|
||||
|
||||
|
||||
###################################
|
||||
# Storage the posts' lastmod.
|
||||
#
|
||||
@@ -67,20 +64,18 @@ _dump() {
|
||||
echo " lastmod: '$_lasmod'" >> "$OUTPUT_DIR/$OUTPUT_FILE"
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
|
||||
_init
|
||||
|
||||
local _count=0
|
||||
|
||||
for _file in $(find ${POST_DIR} -type f \( -iname \*.md -o -iname \*.markdown \))
|
||||
do
|
||||
_filename="$(basename "$_file" | sed 's/-\-\+/-/;s/[[:digit:]]\([[:digit:]]*-\)//g;s/\..*//' )" # remove date and extension
|
||||
for _file in $(find ${POST_DIR} -type f \( -iname \*.md -o -iname \*.markdown \)); do
|
||||
_filename="$(basename "$_file" | sed 's/-\-\+/-/;s/[[:digit:]]\([[:digit:]]*-\)//g;s/\..*//')" # remove date and extension
|
||||
|
||||
if _has_changed "$_file"; then
|
||||
_dump "$_filename" "$_file"
|
||||
((_count=_count+1))
|
||||
((_count = _count + 1))
|
||||
fi
|
||||
|
||||
done
|
||||
@@ -90,5 +85,4 @@ main() {
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
main
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
# $3 -> the destination sync directory
|
||||
|
||||
# Omit the system temp file
|
||||
if [[ ! -f "$1" ]]; then
|
||||
if [[ ! -f $1 ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -21,18 +21,17 @@ dir_prefix="$(realpath "$2")/"
|
||||
|
||||
related_dir="${src_dir:${#dir_prefix}}"
|
||||
|
||||
|
||||
dest="$(realpath "$3")/${related_dir}"
|
||||
|
||||
if [[ ! -d "$dest" ]]; then
|
||||
if [[ ! -d $dest ]]; then
|
||||
mkdir -p "$dest"
|
||||
fi
|
||||
|
||||
if [[ -f "$1" ]]; then
|
||||
if [[ -f $1 ]]; then
|
||||
cp "$1" "$dest"
|
||||
fi
|
||||
|
||||
if [[ "$related_dir" == "_posts" ]]; then
|
||||
if [[ $related_dir == "_posts" ]]; then
|
||||
bash "$3"/_scripts/sh/create_pages.sh
|
||||
bash "$3"/_scripts/sh/dump_lastmod.sh
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user