Skip to content

Commit e130881

Browse files
committed
feat: no regex on title
1 parent 864fe31 commit e130881

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

www/fssg

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ parse_markdown() {
184184
!in_code&&/^[[:space:]]*<[Ss][Tt][Yy][Ll][Ee]/{if(!in_style){close_para();close_blocks();close_lists_to(0)}in_style=1}
185185
in_script||in_style{print;if(in_script&&/<\/[Ss][Cc][Rr][Ii][Pp][Tt]>/)in_script=0;if(in_style&&/<\/[Ss][Tt][Yy][Ll][Ee]>/)in_style=0;next}
186186
/^[[:space:]]*```/{if(in_code){print "</code></pre>";in_code=0}else{close_para();close_blocks();close_lists_to(0);line=$0;sub(/^[[:space:]]*```[[:space:]]*/,"",line);lang=line;sub(/[[:space:]]*$/,"",lang);if(lang!="")printf "<pre><code class=\"language-"lang"\">";else printf "<pre><code>";in_code=1}next}
187-
in_code{gsub(/&/,"\\&amp;",$0);gsub(/</,"\\&lt;",$0);gsub(/>/,"\\&gt;",$0);print;next}
187+
in_code{gsub(/&/,"\\&amp;",$0);gsub(/</,"\\&lt;",$0);gsub(/>,"\\&gt;",$0);print;next}
188188
in_html_block{print;if(is_closing_html($0))in_html_block=0;next}
189189
is_block_html($0){close_para();close_blocks();close_lists_to(0);print;if($0!~/<\/(div|header|footer|nav|section|article|aside|main|form|table|ul|ol|dl|pre|blockquote|h[1-6]|p|hr|address|fieldset|figure)>/)in_html_block=1;next}
190190
/^[[:space:]]*$/{close_para();close_blocks();if(in_bq){print"</blockquote>";in_bq=0};next}
@@ -297,7 +297,7 @@ run_template_processor() {
297297
}
298298
FILENAME=="-"{ content[++content_c]=$0; next }
299299
{
300-
line=$0; gsub(/\{\{[[:space:]]*title[[:space:]]*\}\}/, template_title_value, line)
300+
line=$0; gsub(/\{\{title\}\}/, template_title_value, line)
301301
gsub(/\{\{[[:space:]]*BASE_URL[[:space:]]*\}\}/, BASE_URL, line)
302302
if(state=="INCLUDE_BLOCK"){
303303
if(line~/\{\{[[:space:]]*endinclude/){
@@ -493,23 +493,25 @@ process_file() {
493493
rel_path="${src_file#src/}"
494494
extension="${src_file##*.}"
495495
out_file="dist/${rel_path%.*}.html"
496+
496497
mkdir -p "$(dirname "$out_file")" ||
497498
{
498499
log_error "Failed to create directory for $out_file"
499500
return 1
500501
}
502+
501503
base_name=$(basename "$src_file" ."$extension")
502504
pretty_title=$(
503505
echo "$base_name" | tr '-' ' ' |
504506
$AWK_CMD '{for(i=1;i<=NF;i++)$i=toupper(substr($i,1,1))tolower(substr($i,2));}1'
505507
)
506-
507508
raw_content=$(cat "$src_file")
508509
override_title=$(
509510
echo "$raw_content" 2>/dev/null |
510-
$AWK_CMD '/\{\{ *[Tt]itle:/ {sub(/.*\{\{.*:/,"");sub(/\}\}.*/,"");print;exit}'
511+
$AWK_CMD '/\{\{title:/ {sub(/.*\{\{.*:/,"");sub(/\}\}.*/,"");print;exit}'
511512
)
512513
final_title="${override_title:-$pretty_title}"
514+
513515
page_id="${rel_path%.*}.html"
514516
template_file="src/template.html"
515517
if ! [ -f "$template_file" ]; then
@@ -554,14 +556,14 @@ process_file() {
554556
if [ "$extension" = "md" ] && [ "$is_pre_rendered_html" -eq 0 ]; then
555557
body_html=$(
556558
echo "$content_directives_processed" |
557-
sed 's/{{ *[Tt]itle:[^}]*}}//g' |
559+
sed 's/{{title:[^}]*}}//g' |
558560
parse_markdown
559561
)
560562
else
561563
# Otherwise, just remove the title tag and pass through.
562564
body_html=$(
563565
echo "$content_directives_processed" |
564-
sed 's/{{ *[Tt]itle:[^}]*}}//g'
566+
sed 's/{{title:[^}]*}}//g'
565567
)
566568
fi
567569

@@ -615,7 +617,7 @@ if (location.hostname==="localhost"||location.hostname==="127.0.0.1"){
615617
fi
616618

617619
echo "$processed_content" | minify_and_write "$out_file"
618-
log_verbose "Finished: $src_file -> $out_file"
620+
log_verbose "Finished: $src_file -> $out_file"
619621
return 0
620622
}
621623

@@ -949,4 +951,4 @@ main() {
949951
}
950952

951953
main "$@"
952-
# vim: set tabstop=2 shiftwidth=2 expandtab:
954+
# vim: set tabstop=2 shiftwidth=2 expandtab:

0 commit comments

Comments
 (0)