diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/build_content.sh | 222 | ||||
| -rwxr-xr-x | scripts/build_fonts.sh | 19 | ||||
| -rwxr-xr-x | scripts/build_sass.sh | 6 | ||||
| -rwxr-xr-x | scripts/deploy.sh | 6 | ||||
| -rw-r--r-- | scripts/metadata_filter.lua | 222 | ||||
| -rw-r--r-- | scripts/subpages.jq | 8 | ||||
| -rwxr-xr-x | scripts/watch_content.sh | 14 | ||||
| -rwxr-xr-x | scripts/watch_filters.sh | 9 | ||||
| -rwxr-xr-x | scripts/watch_metadata.sh | 9 | ||||
| -rwxr-xr-x | scripts/watch_sass.sh | 9 | ||||
| -rwxr-xr-x | scripts/watch_templates.sh | 9 |
11 files changed, 75 insertions, 458 deletions
diff --git a/scripts/build_content.sh b/scripts/build_content.sh deleted file mode 100755 index 3dea44f..0000000 --- a/scripts/build_content.sh +++ /dev/null | |||
| @@ -1,222 +0,0 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | source "site.defaults.conf" | ||
| 4 | |||
| 5 | get_filters() { | ||
| 6 | local filters_args="" | ||
| 7 | |||
| 8 | mapfile -d $'\0' filters < <(find $FILTERS_DIR \ | ||
| 9 | -type f \ | ||
| 10 | -name "*.lua" ! -name ".*" \ | ||
| 11 | -print0) | ||
| 12 | |||
| 13 | for file in "${filters[@]}"; do | ||
| 14 | filters_args="$filters_args --lua-filter $file" | ||
| 15 | done | ||
| 16 | |||
| 17 | echo "$filters_args" | ||
| 18 | } | ||
| 19 | |||
| 20 | FILTERS=$(get_filters) | ||
| 21 | |||
| 22 | get_filename_out() { | ||
| 23 | local filename=$1 | ||
| 24 | filename=${filename#"$CONTENT_DIR"} | ||
| 25 | echo "$OUTPUT_DIR$filename" | ||
| 26 | } | ||
| 27 | |||
| 28 | get_metadata() { | ||
| 29 | pandoc "$1" \ | ||
| 30 | -f markdown-citations \ | ||
| 31 | -t plain \ | ||
| 32 | --metadata content_dir="$CONTENT_DIR" \ | ||
| 33 | --metadata file_in="$1" \ | ||
| 34 | --metadata relative_to="$2" \ | ||
| 35 | --metadata-file metadata/metadata.yaml \ | ||
| 36 | --no-highlight \ | ||
| 37 | --template scripts/metadata_tpl.json \ | ||
| 38 | --lua-filter scripts/metadata_filter.lua | ||
| 39 | } | ||
| 40 | |||
| 41 | get_content() { | ||
| 42 | pandoc "$1" \ | ||
| 43 | -f markdown-citations \ | ||
| 44 | -t markdown \ | ||
| 45 | --metadata content_dir="$CONTENT_DIR" \ | ||
| 46 | --metadata file_in="$1" \ | ||
| 47 | --metadata-file metadata/metadata.yaml \ | ||
| 48 | --no-highlight \ | ||
| 49 | --lua-filter scripts/metadata_filter.lua | ||
| 50 | } | ||
| 51 | |||
| 52 | get_subpages_metadata() { | ||
| 53 | local base_dir_in=${1%/index.md} | ||
| 54 | local relative_to="$2" | ||
| 55 | if [ -z "$2" ]; then | ||
| 56 | relative_to="$1" | ||
| 57 | fi | ||
| 58 | local child_pages=() | ||
| 59 | |||
| 60 | if [ -d "$base_dir_in" ]; then | ||
| 61 | mapfile -d $'\0' child_pages < <(find "$base_dir_in" \ | ||
| 62 | -maxdepth 2 \ | ||
| 63 | -type f \ | ||
| 64 | -wholename "$base_dir_in/*/index.md" \ | ||
| 65 | ! -name "_*.md" \ | ||
| 66 | -print0) | ||
| 67 | fi | ||
| 68 | |||
| 69 | local pages="[]" | ||
| 70 | local subsections="{}" | ||
| 71 | |||
| 72 | for file_in in "${child_pages[@]}"; do | ||
| 73 | local subsection=$(basename "${file_in%/index.md}") | ||
| 74 | local content=$(get_content "$file_in" | sed -z 's/\\/\\\\/g;s/\n/\\n/g;s/"/\\"/g') | ||
| 75 | local metadata=$(get_metadata "$file_in" | jq "{ \ | ||
| 76 | file_out: .file_out, \ | ||
| 77 | url: .url, \ | ||
| 78 | author: .author, \ | ||
| 79 | title: .title, \ | ||
| 80 | date: .date, \ | ||
| 81 | last_update: .last_update, \ | ||
| 82 | category: .category, \ | ||
| 83 | preview: .preview, \ | ||
| 84 | content: \"$content\" \ | ||
| 85 | } | del(.[] | nulls)") | ||
| 86 | local title=$(echo "$metadata" | jq ".title") | ||
| 87 | local subpages="[]" | ||
| 88 | |||
| 89 | if [ -z "$2" ]; then | ||
| 90 | subpages=$(get_subpages_metadata "$file_in" "$1" | jq ".pages") | ||
| 91 | fi | ||
| 92 | |||
| 93 | pages=$(echo "$pages" | jq ". += [ $metadata ]") | ||
| 94 | subsections=$(echo "$subsections" | jq ". += { \"$subsection\": { title: $title, pages: $subpages } }") | ||
| 95 | done | ||
| 96 | |||
| 97 | echo "{ \"pages\": $pages, \"subsections\": $subsections }" | ||
| 98 | } | ||
| 99 | |||
| 100 | handle () { | ||
| 101 | if [ "${1#*.}" = "md" ]; then | ||
| 102 | local included_metadata=$(get_metadata "$1") | ||
| 103 | local file_out=$(echo "$included_metadata" | jq -r .file_out) | ||
| 104 | file_out="$OUTPUT_DIR${file_out#/}" | ||
| 105 | local create_feed=$(echo "$included_metadata" | jq -r .create_feed) | ||
| 106 | |||
| 107 | mkdir -p $(dirname "$file_out") | ||
| 108 | |||
| 109 | echo -e "\033[0;32m[COMPILE ]\033[0m $1 -> $file_out" | ||
| 110 | |||
| 111 | echo -e "\033[0;90m[COMPILE ]\033[0m Getting subpages" | ||
| 112 | |||
| 113 | local added_metadata=$(get_subpages_metadata "$1") | ||
| 114 | |||
| 115 | local meta_file=$(mktemp) | ||
| 116 | |||
| 117 | echo "$added_metadata" > "$meta_file" | ||
| 118 | |||
| 119 | if [ "$create_feed" = "true" ]; then | ||
| 120 | echo -e "\033[0;90m[COMPILE ]\033[0m Creating feed" | ||
| 121 | |||
| 122 | pandoc "$1" \ | ||
| 123 | -f markdown-citations \ | ||
| 124 | -t html5 \ | ||
| 125 | --no-highlight \ | ||
| 126 | --template "${TEMPLATES_DIR}feed.xml" \ | ||
| 127 | -o "${file_out%.html}.xml" \ | ||
| 128 | --metadata content_dir="$CONTENT_DIR" \ | ||
| 129 | --metadata file_in="$1" \ | ||
| 130 | --metadata page_type=feed \ | ||
| 131 | --metadata-file metadata/metadata.yaml \ | ||
| 132 | --metadata-file "$meta_file" \ | ||
| 133 | --lua-filter scripts/metadata_filter.lua | ||
| 134 | fi | ||
| 135 | |||
| 136 | echo -e "\033[0;90m[COMPILE ]\033[0m Creating page" | ||
| 137 | |||
| 138 | pandoc "$1" \ | ||
| 139 | -f markdown-citations \ | ||
| 140 | -t html5 \ | ||
| 141 | --no-highlight \ | ||
| 142 | --template "${TEMPLATES_DIR}base.html" \ | ||
| 143 | -o "$file_out" \ | ||
| 144 | --metadata content_dir="$CONTENT_DIR" \ | ||
| 145 | --metadata file_in="$1" \ | ||
| 146 | --metadata-file metadata/metadata.yaml \ | ||
| 147 | --metadata-file "$meta_file" \ | ||
| 148 | --lua-filter scripts/metadata_filter.lua \ | ||
| 149 | $FILTERS | ||
| 150 | |||
| 151 | # echo "$(pandoc "$1" \ | ||
| 152 | # -f markdown-citations \ | ||
| 153 | # -t plain \ | ||
| 154 | # --no-highlight \ | ||
| 155 | # --template scripts/metadata_tpl.json \ | ||
| 156 | # --metadata content_dir="$CONTENT_DIR" \ | ||
| 157 | # --metadata file_in="$1" \ | ||
| 158 | # --metadata-file metadata/metadata.yaml \ | ||
| 159 | # --metadata-file "$meta_file" \ | ||
| 160 | # --lua-filter scripts/metadata_filter.lua \ | ||
| 161 | # $FILTERS)" | ||
| 162 | |||
| 163 | rm "$meta_file" | ||
| 164 | |||
| 165 | echo -e "\033[0;90m[COMPILE ]\033[0m Done" | ||
| 166 | else | ||
| 167 | local file_out=$(get_filename_out "$1") | ||
| 168 | |||
| 169 | mkdir -p $(dirname "$file_out") | ||
| 170 | |||
| 171 | echo -e "\033[0;32m[COPY ]\033[0m $1 -> $file_out" | ||
| 172 | |||
| 173 | cp "$1" "$file_out" | ||
| 174 | fi | ||
| 175 | } | ||
| 176 | |||
| 177 | mdfilter="" | ||
| 178 | if [ "$LIVE" != true ]; then | ||
| 179 | mdfilter="! -name _*.md" | ||
| 180 | fi | ||
| 181 | |||
| 182 | if [ -z "$1" ]; then | ||
| 183 | find "$CONTENT_DIR" \ | ||
| 184 | -type f \ | ||
| 185 | ! -name ".*" \ | ||
| 186 | $mdfilter \ | ||
| 187 | | while read file_in | ||
| 188 | do | ||
| 189 | handle "$file_in" | ||
| 190 | done | ||
| 191 | elif [ "$1" = "all_md" ]; then | ||
| 192 | find "$CONTENT_DIR" \ | ||
| 193 | -type f \ | ||
| 194 | -name "*.md" \ | ||
| 195 | ! -name ".*" \ | ||
| 196 | $mdfilter \ | ||
| 197 | | while read file_in | ||
| 198 | do | ||
| 199 | handle "$file_in" | ||
| 200 | done | ||
| 201 | elif [ "$1" = "single" ]; then | ||
| 202 | if [ -z "$2" ]; then | ||
| 203 | echo -e "\033[0;31m[ERROR ]\033[0m \"single\" operation requires file argument" | ||
| 204 | else | ||
| 205 | filename=$(basename "$2") | ||
| 206 | if [ "${filename:0:1}" != "_" ]; then | ||
| 207 | handle "$2" | ||
| 208 | fi | ||
| 209 | fi | ||
| 210 | elif [ "$1" = "delete" ]; then | ||
| 211 | if [ -z "$2" ]; then | ||
| 212 | echo -e "\033[0;31m[ERROR ]\033[0m \"delete\" operation requires file argument" | ||
| 213 | else | ||
| 214 | file_out=$(get_filename_out "$2") | ||
| 215 | if [ -f "$file_out" ] || [ -d "$file_out" ]; then | ||
| 216 | echo -e "\033[0;32m[DELETE ]\033[0m $2 -> $file_out" | ||
| 217 | rm -rf $file_out | ||
| 218 | fi | ||
| 219 | fi | ||
| 220 | else | ||
| 221 | echo -e "\033[0;31m[ERROR ]\033[0m Unknown operation: \"$1\"" | ||
| 222 | fi | ||
diff --git a/scripts/build_fonts.sh b/scripts/build_fonts.sh deleted file mode 100755 index 7d368e7..0000000 --- a/scripts/build_fonts.sh +++ /dev/null | |||
| @@ -1,19 +0,0 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | source "site.defaults.conf" | ||
| 4 | |||
| 5 | find "${ASSETS_DIR}fonts" \ | ||
| 6 | -type f \ | ||
| 7 | -name "*.ttf" \ | ||
| 8 | | while read file | ||
| 9 | do | ||
| 10 | target_file=$(basename "${file%.ttf}.woff2") | ||
| 11 | |||
| 12 | echo -e "\033[0;32m[MINIFY ]\033[0m $file -> $OUTPUT_DIR$target_file" | ||
| 13 | |||
| 14 | pyftsubset "$file" \ | ||
| 15 | --text-file="${ASSETS_DIR}fonts/glyphs.txt" \ | ||
| 16 | --layout-features+=ss02,ss09,dlig \ | ||
| 17 | --flavor="woff2" \ | ||
| 18 | --output-file="$OUTPUT_DIR$target_file" | ||
| 19 | done | ||
diff --git a/scripts/build_sass.sh b/scripts/build_sass.sh deleted file mode 100755 index 3f5f768..0000000 --- a/scripts/build_sass.sh +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | source "site.defaults.conf" | ||
| 4 | |||
| 5 | echo -e "\033[0;32m[COMPILE ]\033[0m ${ASSETS_DIR}css/style.scss -> ${OUTPUT_DIR}style.css" | ||
| 6 | sassc -t compressed ${ASSETS_DIR}css/style.scss | ./node_modules/.bin/postcss --use autoprefixer --no-map > "${OUTPUT_DIR}style.css" | ||
diff --git a/scripts/deploy.sh b/scripts/deploy.sh deleted file mode 100755 index a810b74..0000000 --- a/scripts/deploy.sh +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | source "site.defaults.conf" | ||
| 4 | |||
| 5 | echo -e "\033[0;32m[DEPLOY ]\033[0m $DEPLOY_TARGET" | ||
| 6 | rsync --progress --stats -rvz --delete "$OUTPUT_DIR" "$DEPLOY_TARGET" | ||
diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua index 90ca465..21f7759 100644 --- a/scripts/metadata_filter.lua +++ b/scripts/metadata_filter.lua | |||
| @@ -5,27 +5,21 @@ function format_date(date) | |||
| 5 | local year, month, day = date:match("(%d%d%d%d)-(%d%d)-(%d%d)") | 5 | local year, month, day = date:match("(%d%d%d%d)-(%d%d)-(%d%d)") |
| 6 | if year == nil then return nil end | 6 | if year == nil then return nil end |
| 7 | 7 | ||
| 8 | local time = os.time({ | 8 | local time = os.time({year = tonumber(year), month = tonumber(month), day = tonumber(day)}) |
| 9 | year = tonumber(year), | ||
| 10 | month = tonumber(month), | ||
| 11 | day = tonumber(day) | ||
| 12 | }) | ||
| 13 | return pandoc.MetaMap({ | 9 | return pandoc.MetaMap({ |
| 14 | yyyy_mm_dd = pandoc.MetaString(os.date("%F", time)), | 10 | yyyy_mm_dd = os.date("%F", time), |
| 15 | yyyy = pandoc.MetaString(os.date("%Y", time)), | 11 | yyyy = os.date("%Y", time), |
| 16 | mm = pandoc.MetaString(os.date("%m", time)), | 12 | mm = os.date("%m", time), |
| 17 | dd = pandoc.MetaString(os.date("%d", time)), | 13 | dd = os.date("%d", time), |
| 18 | rfc3339 = pandoc.MetaString(os.date("%FT%T+00:00", time)), | 14 | rfc3339 = os.date("%FT%T+00:00", time), |
| 19 | long = pandoc.MetaString(os.date("%B %d, %Y", time)), | 15 | long = os.date("%B %d, %Y", time), |
| 20 | }) | 16 | }) |
| 21 | end | 17 | end |
| 22 | 18 | ||
| 23 | function table_to_list(t, cmp) | 19 | function table_to_list(t, cmp) |
| 24 | local l = pandoc.List() | 20 | local l = pandoc.List() |
| 25 | 21 | ||
| 26 | for key, value in pairs(t) do | 22 | for key, value in pairs(t) do l:insert(pandoc.MetaMap({key = key, value = value})) end |
| 27 | l:insert(pandoc.MetaMap({key = key, value = value})) | ||
| 28 | end | ||
| 29 | 23 | ||
| 30 | l:sort(cmp or function(i1, i2) return i1.key < i2.key end) | 24 | l:sort(cmp or function(i1, i2) return i1.key < i2.key end) |
| 31 | 25 | ||
| @@ -83,9 +77,7 @@ function relative_to(dir, target) | |||
| 83 | end | 77 | end |
| 84 | 78 | ||
| 85 | if #dir < #target then | 79 | if #dir < #target then |
| 86 | for i = #dir + 1, #target do | 80 | for i = #dir + 1, #target do path = path .. (path == "" and "" or "/") .. target[i] end |
| 87 | path = path .. (path == "" and "" or "/") .. target[i] | ||
| 88 | end | ||
| 89 | elseif #dir > #target then | 81 | elseif #dir > #target then |
| 90 | for _ = #target + 1, #dir do path = "../" .. path end | 82 | for _ = #target + 1, #dir do path = "../" .. path end |
| 91 | end | 83 | end |
| @@ -93,31 +85,8 @@ function relative_to(dir, target) | |||
| 93 | return path | 85 | return path |
| 94 | end | 86 | end |
| 95 | 87 | ||
| 96 | function apply_path_rewrites(rewrites, str) | ||
| 97 | for i = 1, #rewrites.path do | ||
| 98 | local r = rewrites.path[i] | ||
| 99 | str = str:gsub(pandoc.utils.stringify(r.from), | ||
| 100 | pandoc.utils.stringify(r.to)) | ||
| 101 | end | ||
| 102 | return str | ||
| 103 | end | ||
| 104 | |||
| 105 | function get_file_out(rewrites, content_dir, file_in) | ||
| 106 | local file_out = file_in:gsub("^" .. content_dir, ""):gsub("%.md$", ".html") | ||
| 107 | |||
| 108 | if file_out:match(".html$") and not file_out:match("/index%.html$") then | ||
| 109 | file_out = file_out:gsub("/(.*)%.html$", "/%1/index.html") | ||
| 110 | end | ||
| 111 | |||
| 112 | file_out = apply_path_rewrites(rewrites, file_out) | ||
| 113 | |||
| 114 | return pandoc.MetaString(file_out) | ||
| 115 | end | ||
| 116 | |||
| 117 | function make_absolute(rel, base) | 88 | function make_absolute(rel, base) |
| 118 | return | 89 | return rel:find("^/") ~= nil and rel or base:gsub("^(.*)/.-$", "%1") .. "/" .. rel |
| 119 | rel:find("^/") ~= nil and rel or base:gsub("^(.*)/.-$", "%1") .. "/" .. | ||
| 120 | rel | ||
| 121 | end | 90 | end |
| 122 | 91 | ||
| 123 | function resolve_url(site_url, ref_file, target_file) | 92 | function resolve_url(site_url, ref_file, target_file) |
| @@ -127,119 +96,82 @@ function resolve_url(site_url, ref_file, target_file) | |||
| 127 | local abs = target_file | 96 | local abs = target_file |
| 128 | local rel = relative_to(ref_base_dir, abs):gsub("/index%.html$", "/") | 97 | local rel = relative_to(ref_base_dir, abs):gsub("/index%.html$", "/") |
| 129 | 98 | ||
| 130 | return pandoc.MetaMap({ | 99 | return pandoc.MetaMap({abs = abs, rel = rel, full = (site_url .. abs)}) |
| 131 | abs = pandoc.MetaString(abs), | ||
| 132 | rel = pandoc.MetaString(rel), | ||
| 133 | full = pandoc.MetaString(site_url .. abs) | ||
| 134 | }) | ||
| 135 | end | 100 | end |
| 136 | 101 | ||
| 137 | function resolve_layout(layout) | 102 | function resolve_layout(layout) |
| 138 | if layout then | 103 | if layout ~= nil then |
| 139 | layout = pandoc.utils.stringify(layout) | 104 | layout = pandoc.utils.stringify(layout) |
| 140 | return pandoc.MetaMap({ | 105 | return pandoc.MetaMap({id = layout, ["is_" .. layout] = pandoc.MetaBool(true)}) |
| 141 | id = pandoc.MetaString(layout), | ||
| 142 | ["is_" .. layout] = pandoc.MetaBool(true) | ||
| 143 | }) | ||
| 144 | end | 106 | end |
| 145 | end | 107 | end |
| 146 | 108 | ||
| 147 | function resolve_section(content_dir, file_in) | 109 | function resolve_namespace(namespace) |
| 148 | local section = file_in:gsub("^" .. content_dir, ""):match("^/(.-)[/.]") or | 110 | namespace = pandoc.utils.stringify(namespace) |
| 149 | "index" | 111 | |
| 112 | local root = "index" | ||
| 113 | if namespace ~= "" then root = namespace:gsub("^/([^/]*).*$", "%1") end | ||
| 114 | |||
| 150 | return pandoc.MetaMap({ | 115 | return pandoc.MetaMap({ |
| 151 | id = pandoc.MetaString(section), | 116 | root = pandoc.MetaMap({id = root, ["is_" .. root] = pandoc.MetaBool(true)}), |
| 152 | ["is_" .. section] = pandoc.MetaBool(true) | 117 | full = namespace, |
| 153 | }) | 118 | }) |
| 154 | end | 119 | end |
| 155 | 120 | ||
| 156 | function resolve_category(categories, category) | 121 | function resolve_category(categories, category) |
| 157 | if categories and category then | 122 | if categories ~= nil and category ~= nil then |
| 158 | category = pandoc.utils.stringify(category) | 123 | category = pandoc.utils.stringify(category) |
| 159 | data = pandoc.MetaMap(categories[category]) | 124 | data = pandoc.MetaMap(categories[category]) |
| 160 | data.id = pandoc.MetaString(category) | 125 | data.id = category |
| 161 | return data | 126 | return data |
| 162 | end | 127 | end |
| 163 | end | 128 | end |
| 164 | 129 | ||
| 165 | function prep_main_menu(rewrites, section, main_menu) | 130 | function prep_menu(active_id, main_menu) |
| 166 | local active_item = nil | 131 | local active_item = nil |
| 167 | 132 | ||
| 168 | for i = 1, #main_menu do | 133 | for i = 1, #main_menu do |
| 169 | local item = main_menu[i] | 134 | local item = main_menu[i] |
| 170 | local active = pandoc.utils.stringify(item.id) == section.id | 135 | local active = pandoc.utils.stringify(item.id) == active_id |
| 171 | item.active = pandoc.MetaBool(active) | 136 | item.active = pandoc.MetaBool(active) |
| 172 | item.url = apply_path_rewrites(rewrites, | ||
| 173 | pandoc.utils.stringify(item.url)) | ||
| 174 | if active then active_item = item end | 137 | if active then active_item = item end |
| 175 | end | 138 | end |
| 176 | 139 | ||
| 177 | return pandoc.MetaMap({ | 140 | return pandoc.MetaMap({ |
| 178 | items = main_menu:filter(function(item) | 141 | items = main_menu:filter(function(item) return not item.hidden or item.active end), |
| 179 | return not item.hidden or item.active | 142 | active = active_item, |
| 180 | end), | ||
| 181 | active = active_item | ||
| 182 | }) | 143 | }) |
| 183 | end | 144 | end |
| 184 | 145 | ||
| 185 | function organize_subpages(site_url, ref_file, pages) | 146 | function process_pages(global, pages_by_id) |
| 186 | for i = 1, #pages do | 147 | if pages_by_id == nil then pages_by_id = {} end |
| 187 | local page = pages[i] | ||
| 188 | page.url = resolve_url(site_url, ref_file, | ||
| 189 | pandoc.utils.stringify(page.file_out)) | ||
| 190 | end | ||
| 191 | |||
| 192 | local pages_grouped_date = | ||
| 193 | group_by(pages, function(p) return not p.date end) | ||
| 194 | |||
| 195 | local pages_undated = pages_grouped_date[true] or pandoc.MetaList({}) | ||
| 196 | pages_undated:sort(function(p1, p2) | ||
| 197 | return pandoc.utils.stringify(p1.title) < | ||
| 198 | pandoc.utils.stringify(p2.title) | ||
| 199 | end) | ||
| 200 | 148 | ||
| 201 | local pages_dated = pages_grouped_date[false] or pandoc.MetaList({}) | 149 | local pages_list = pandoc.List() |
| 202 | pages_dated:sort(function(p1, p2) | ||
| 203 | return pandoc.utils.stringify(p1.date.yyyy_mm_dd) > | ||
| 204 | pandoc.utils.stringify(p2.date.yyyy_mm_dd) | ||
| 205 | end) | ||
| 206 | 150 | ||
| 207 | local pages_categorized = pages:filter( | 151 | for _, page in pairs(pages_by_id) do |
| 208 | function(p) return p.category ~= nil end) | 152 | page = process(global, page) |
| 209 | pages_categorized:sort(function(p1, p2) | 153 | pages_list:insert(page) |
| 210 | return pandoc.utils.stringify(p1.title) < | 154 | end |
| 211 | pandoc.utils.stringify(p2.title) | ||
| 212 | end) | ||
| 213 | 155 | ||
| 214 | local pages_by_year = group_by(pages_dated, function(p) | 156 | local pages_categorized = pages_list:filter(function(p) return p.category ~= nil end) |
| 215 | return pandoc.utils.stringify(p.date.yyyy) | 157 | pages_categorized:sort(function(p1, p2) return p1.title < p2.title end) |
| 216 | end) | ||
| 217 | pages_by_year = pandoc.MetaList(table_to_list(pages_by_year, | ||
| 218 | function(i1, i2) | ||
| 219 | return i1.key > i2.key | ||
| 220 | end)) | ||
| 221 | 158 | ||
| 222 | local pages_by_category = group_by(pages_categorized, function(p) | 159 | local pages_by_category = group_by(pages_categorized, |
| 223 | return pandoc.utils.stringify(p.category.id) | 160 | function(p) return pandoc.utils.stringify(p.category.id) end) |
| 224 | end) | ||
| 225 | pages_by_category = pandoc.MetaList(table_to_list(pages_by_category, | 161 | pages_by_category = pandoc.MetaList(table_to_list(pages_by_category, |
| 226 | function(i1, i2) | 162 | function(i1, i2) return i1.key < i2.key end)) |
| 227 | return i1.key < i2.key | ||
| 228 | end)) | ||
| 229 | 163 | ||
| 230 | local pages_data = pandoc.MetaMap({ | 164 | local pages_data = pandoc.MetaMap({ |
| 231 | all_dated = pages_dated, | 165 | all = pages_list, |
| 232 | all_undated = pages_undated, | 166 | by_id = pages_by_id, |
| 233 | by_year = pages_by_year, | ||
| 234 | by_category = pages_by_category, | 167 | by_category = pages_by_category, |
| 235 | last_update = #pages_dated ~= 0 and pages_dated[1].last_update | ||
| 236 | }) | 168 | }) |
| 237 | 169 | ||
| 238 | local categories_data = group_by(pages_categorized, function(p) | 170 | local categories_data = group_by(pages_categorized, function(p) |
| 239 | return p.category and pandoc.utils.stringify(p.category.id) | 171 | return p.category and pandoc.utils.stringify(p.category.id) |
| 240 | end, function(stats, _, p) | 172 | end, function(stats, _, p) |
| 241 | if not stats then | 173 | if not stats then |
| 242 | return {name = pandoc.MetaString(p.category.name), count = 1} | 174 | return {name = p.category.name, count = 1} |
| 243 | else | 175 | else |
| 244 | stats.count = stats.count + 1 | 176 | stats.count = stats.count + 1 |
| 245 | end | 177 | end |
| @@ -247,72 +179,52 @@ function organize_subpages(site_url, ref_file, pages) | |||
| 247 | categories_data = pandoc.MetaList(table_to_list(categories_data)) | 179 | categories_data = pandoc.MetaList(table_to_list(categories_data)) |
| 248 | 180 | ||
| 249 | for i = 1, #categories_data do | 181 | for i = 1, #categories_data do |
| 250 | categories_data[i].value.count = | 182 | categories_data[i].value.count = ("%d"):format(categories_data[i].value.count) |
| 251 | pandoc.MetaString(("%d"):format(categories_data[i].value.count)) | ||
| 252 | end | 183 | end |
| 253 | 184 | ||
| 254 | return pages_data, categories_data | 185 | return pages_data, categories_data |
| 255 | end | 186 | end |
| 256 | 187 | ||
| 257 | function Meta(meta) | 188 | function process(global, meta) |
| 258 | meta.content_dir = meta.content_dir:gsub("/$", "") | 189 | meta.namespace = resolve_namespace(meta.namespace) |
| 259 | meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") | 190 | meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") |
| 260 | meta.rewrites = meta.rewrites or | ||
| 261 | pandoc.MetaMap({path = pandoc.MetaList({})}) | ||
| 262 | meta.page_type = meta.page_type or "page" | ||
| 263 | meta.layout = resolve_layout(meta.layout) | 191 | meta.layout = resolve_layout(meta.layout) |
| 264 | meta.section = resolve_section(meta.content_dir, meta.file_in) | 192 | meta.url = resolve_url(global.site.url, global.file_out, meta.file_out) |
| 265 | 193 | ||
| 266 | meta.file_out = get_file_out(meta.rewrites, meta.content_dir, meta.file_in) | 194 | if meta.title ~= nil then |
| 267 | if meta.relative_to == nil then meta.relative_to = meta.file_in end | 195 | meta.title = pandoc.utils.stringify(meta.title) |
| 268 | meta.relative_to_out = get_file_out(meta.rewrites, meta.content_dir, | 196 | else |
| 269 | meta.relative_to) | 197 | meta.title = "" |
| 198 | end | ||
| 270 | 199 | ||
| 271 | meta.url = resolve_url(meta.site.url, meta.relative_to_out, meta.file_out) | ||
| 272 | if meta.preview ~= nil then | 200 | if meta.preview ~= nil then |
| 273 | meta.preview = resolve_url(meta.site.url, meta.relative_to_out, | 201 | meta.preview = make_absolute(pandoc.utils.stringify(meta.preview), meta.file_out) |
| 274 | make_absolute( | 202 | meta.preview = resolve_url(global.site.url, global.file_out, meta.preview) |
| 275 | pandoc.utils.stringify(meta.preview), | ||
| 276 | meta.file_out)) | ||
| 277 | end | 203 | end |
| 278 | 204 | ||
| 279 | meta.date = format_date(meta.date) | 205 | if meta.date ~= nil then meta.date = format_date(meta.date) end |
| 206 | |||
| 280 | if meta.last_update ~= nil then | 207 | if meta.last_update ~= nil then |
| 281 | meta.last_update = format_date(meta.last_update) | 208 | meta.last_update = format_date(meta.last_update) |
| 282 | else | 209 | else |
| 283 | meta.last_update = meta.date | 210 | meta.last_update = meta.date |
| 284 | end | 211 | end |
| 285 | 212 | ||
| 286 | meta.category = resolve_category(meta.categories[meta.section.id], | 213 | meta.category = resolve_category(global.categories[meta.namespace.root.id], meta.category) |
| 287 | meta.category) | ||
| 288 | meta.categories = nil | ||
| 289 | 214 | ||
| 290 | if meta.page_type == "feed" then | 215 | if meta.menus ~= nil and meta.menus.main ~= nil then |
| 291 | meta.page = pandoc.MetaMap({ | 216 | meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) |
| 292 | url = resolve_url(meta.site.url, meta.relative_to_out, | ||
| 293 | meta.file_out:gsub("%.xml$", ".html")) | ||
| 294 | }) | ||
| 295 | end | 217 | end |
| 296 | 218 | ||
| 297 | if meta.create_feed then | 219 | local pages, local_categories = process_pages(global, meta.pages) |
| 298 | meta.feed = pandoc.MetaMap({ | 220 | meta.pages = pages |
| 299 | url = resolve_url(meta.site.url, meta.relative_to_out, | 221 | meta.local_categories = local_categories |
| 300 | meta.file_out:gsub("%.html$", ".xml")) | ||
| 301 | }) | ||
| 302 | end | ||
| 303 | 222 | ||
| 304 | if meta.menus and meta.menus.main then | 223 | return meta |
| 305 | meta.menus.main = prep_main_menu(meta.rewrites, meta.section, | 224 | end |
| 306 | meta.menus.main) | ||
| 307 | end | ||
| 308 | 225 | ||
| 309 | if meta.pages then | 226 | function Meta(meta) |
| 310 | local pages, categories = organize_subpages(meta.site.url, | 227 | meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") |
| 311 | meta.relative_to_out, | ||
| 312 | meta.pages) | ||
| 313 | meta.pages = pages | ||
| 314 | meta.categories = categories | ||
| 315 | end | ||
| 316 | 228 | ||
| 317 | return meta | 229 | return process(meta, meta) |
| 318 | end | 230 | end |
diff --git a/scripts/subpages.jq b/scripts/subpages.jq new file mode 100644 index 0000000..4850703 --- /dev/null +++ b/scripts/subpages.jq | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | [ | ||
| 2 | .[] | ||
| 3 | | . as $page | ||
| 4 | | (.namespace | ltrimstr($namespace + "/") | split("/") | (.[] |= ["pages",.]) | flatten) as $path | ||
| 5 | | null | ||
| 6 | | setpath($path; $page) | ||
| 7 | ] | ||
| 8 | | reduce .[] as $item ({}; . * $item) | ||
diff --git a/scripts/watch_content.sh b/scripts/watch_content.sh deleted file mode 100755 index 30f8a6c..0000000 --- a/scripts/watch_content.sh +++ /dev/null | |||
| @@ -1,14 +0,0 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | source "site.defaults.conf" | ||
| 4 | |||
| 5 | inotifywait -qrme close_write,delete,move --format "%w%f" "${CONTENT_DIR%/}" \ | ||
| 6 | | while read file | ||
| 7 | do | ||
| 8 | if [ -f "$file" ]; then | ||
| 9 | # scripts/build_content.sh "single" "$file" | ||
| 10 | scripts/build_content.sh | ||
| 11 | elif [ ! -d "$file" ]; then | ||
| 12 | scripts/build_content.sh "delete" "$file" | ||
| 13 | fi | ||
| 14 | done | ||
diff --git a/scripts/watch_filters.sh b/scripts/watch_filters.sh deleted file mode 100755 index 5dd6ad5..0000000 --- a/scripts/watch_filters.sh +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | source "site.defaults.conf" | ||
| 4 | |||
| 5 | inotifywait -qrme close_write,delete,move --format "%w%f" "${FILTERS_DIR%/}" \ | ||
| 6 | | while read file | ||
| 7 | do | ||
| 8 | scripts/build_content.sh "all_md" | ||
| 9 | done | ||
diff --git a/scripts/watch_metadata.sh b/scripts/watch_metadata.sh deleted file mode 100755 index 2f6efde..0000000 --- a/scripts/watch_metadata.sh +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | source "site.defaults.conf" | ||
| 4 | |||
| 5 | inotifywait -qrme close_write,delete,move --format "%w%f" "${METADATA_DIR%/}" \ | ||
| 6 | | while read file | ||
| 7 | do | ||
| 8 | scripts/build_content.sh "all_md" | ||
| 9 | done | ||
diff --git a/scripts/watch_sass.sh b/scripts/watch_sass.sh deleted file mode 100755 index 7345eb3..0000000 --- a/scripts/watch_sass.sh +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | source "site.defaults.conf" | ||
| 4 | |||
| 5 | inotifywait -qrme close_write,delete,move --format "%w%f" "${ASSETS_DIR}css" \ | ||
| 6 | | while read file | ||
| 7 | do | ||
| 8 | scripts/build_sass.sh | ||
| 9 | done | ||
diff --git a/scripts/watch_templates.sh b/scripts/watch_templates.sh deleted file mode 100755 index 70ae4c3..0000000 --- a/scripts/watch_templates.sh +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | source "site.defaults.conf" | ||
| 4 | |||
| 5 | inotifywait -qrme close_write,delete,move --format "%w%f" "${TEMPLATES_DIR%/}" \ | ||
| 6 | | while read file | ||
| 7 | do | ||
| 8 | scripts/build_content.sh "all_md" | ||
| 9 | done | ||
