diff options
author | Volpeon <git@volpeon.ink> | 2020-12-27 22:03:42 +0100 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2020-12-27 22:03:42 +0100 |
commit | 517fc58cf46595990fd5af64a1bd647ee5ac3c08 (patch) | |
tree | 3720064c91a95230b1208352b9fa63b554e1b0cd /scripts | |
parent | Build script: Improved path and relative link calculation, added vars to conf... (diff) | |
download | volpeon.ink-517fc58cf46595990fd5af64a1bd647ee5ac3c08.tar.gz volpeon.ink-517fc58cf46595990fd5af64a1bd647ee5ac3c08.tar.bz2 volpeon.ink-517fc58cf46595990fd5af64a1bd647ee5ac3c08.zip |
Added stylelint, generate some metadata automatically
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/build_content.sh | 50 | ||||
-rw-r--r-- | scripts/metadata_tpl.json | 4 |
2 files changed, 51 insertions, 3 deletions
diff --git a/scripts/build_content.sh b/scripts/build_content.sh index b7d0c24..5b4bb85 100755 --- a/scripts/build_content.sh +++ b/scripts/build_content.sh | |||
@@ -1,6 +1,7 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | CONTENT_DIR="content/" | 3 | CONTENT_DIR="content/" |
4 | TEMPLATES_DIR="templates/" | ||
4 | OUTPUT_DIR="output/" | 5 | OUTPUT_DIR="output/" |
5 | 6 | ||
6 | target_filename () { | 7 | target_filename () { |
@@ -23,6 +24,22 @@ target_url_rel () { | |||
23 | echo "$filename" | 24 | echo "$filename" |
24 | } | 25 | } |
25 | 26 | ||
27 | target_url_abs () { | ||
28 | url=$(target_url_rel "$CONTENT_DIR" "$1") | ||
29 | echo "/$url" | ||
30 | } | ||
31 | |||
32 | get_section() { | ||
33 | filename=$1 | ||
34 | filename=${filename#"$CONTENT_DIR"} | ||
35 | filename=${filename%.md} | ||
36 | filename=$(echo "$filename" | cut -f1 -d /) | ||
37 | if [ "$filename" = "index.md" ]; then | ||
38 | filename="home" | ||
39 | fi | ||
40 | echo "$filename" | ||
41 | } | ||
42 | |||
26 | get_subpages_basedir() { | 43 | get_subpages_basedir() { |
27 | filename=$1 | 44 | filename=$1 |
28 | if [ "${filename##*/}" = "index.md" ]; then | 45 | if [ "${filename##*/}" = "index.md" ]; then |
@@ -55,20 +72,45 @@ get_subpages() { | |||
55 | if [ ${#child_pages[@]} -ne 0 ]; then | 72 | if [ ${#child_pages[@]} -ne 0 ]; then |
56 | echo -e "\033[0;90m[////////]\033[0m Child pages:" | 73 | echo -e "\033[0;90m[////////]\033[0m Child pages:" |
57 | 74 | ||
75 | collected_metadata="[]" | ||
76 | |||
58 | for file in "${child_pages[@]}"; do | 77 | for file in "${child_pages[@]}"; do |
59 | link=$(target_url_rel "$basedir" "$file") | 78 | echo -e "\033[0;90m[////////]\033[0m - $file" |
60 | echo -e "\033[0;90m[////////]\033[0m - $file -> rel. URL: $link" | 79 | |
80 | url_rel=$(target_url_rel "$basedir" "$file") | ||
81 | url_abs=$(target_url_abs "$file") | ||
82 | |||
83 | metadata=$(pandoc "$file" \ | ||
84 | -f markdown \ | ||
85 | -t plain \ | ||
86 | --template scripts/metadata_tpl.json) | ||
87 | |||
88 | metadata=$(echo "$metadata" | jq ". + { url_rel: \"$url_rel\", url_abs: \"$url_abs\" }") | ||
89 | |||
90 | collected_metadata=$(echo "$collected_metadata" | jq ". + [ $metadata ]") | ||
61 | done | 91 | done |
92 | |||
93 | collected_metadata=$(echo "$collected_metadata" | jq "sort_by(.date)") | ||
94 | |||
95 | echo "$collected_metadata" | ||
62 | fi | 96 | fi |
63 | } | 97 | } |
64 | 98 | ||
65 | handle () { | 99 | handle () { |
66 | target=$(target_filename "$1") | 100 | target=$(target_filename "$1") |
101 | |||
67 | mkdir -p $(dirname "$target") | 102 | mkdir -p $(dirname "$target") |
68 | 103 | ||
69 | if [ "${1#*.}" = "md" ]; then | 104 | if [ "${1#*.}" = "md" ]; then |
70 | echo -e "\033[0;32m[COMPILE ]\033[0m $1 -> $target" | 105 | echo -e "\033[0;32m[COMPILE ]\033[0m $1 -> $target" |
71 | 106 | ||
107 | is_home=false | ||
108 | section=$(get_section "$1") | ||
109 | |||
110 | if [ "$target" = "${OUTPUT_DIR}index.html" ]; then | ||
111 | is_home=true | ||
112 | fi | ||
113 | |||
72 | subpages_meta=$(mktemp) | 114 | subpages_meta=$(mktemp) |
73 | 115 | ||
74 | # $(get_subpages "$1") > "$subpages_meta" | 116 | # $(get_subpages "$1") > "$subpages_meta" |
@@ -78,8 +120,10 @@ handle () { | |||
78 | pandoc "$1" \ | 120 | pandoc "$1" \ |
79 | -f markdown \ | 121 | -f markdown \ |
80 | -t html5 \ | 122 | -t html5 \ |
81 | --template templates/base.html \ | 123 | --template "${TEMPLATES_DIR}base.html" \ |
82 | -o "$target" \ | 124 | -o "$target" \ |
125 | --metadata isHome=$is_home \ | ||
126 | --metadata section=$section \ | ||
83 | --metadata-file metadata/metadata.yaml \ | 127 | --metadata-file metadata/metadata.yaml \ |
84 | --metadata-file "$subpages_meta" | 128 | --metadata-file "$subpages_meta" |
85 | 129 | ||
diff --git a/scripts/metadata_tpl.json b/scripts/metadata_tpl.json new file mode 100644 index 0000000..eeda341 --- /dev/null +++ b/scripts/metadata_tpl.json | |||
@@ -0,0 +1,4 @@ | |||
1 | { | ||
2 | "title": "$title$", | ||
3 | "date": "$date$" | ||
4 | } | ||