diff --git a/awk/headers.awk b/awk/headers.awk
index ceba83d..6362624 100644
--- a/awk/headers.awk
+++ b/awk/headers.awk
@@ -8,18 +8,21 @@ function strip_markdown(s) {
return s
}
function print_header(line) {
- if (line ~ /^# /) {
- sub(/^# /, "", line); print "
" line "
"
- } else if (line ~ /^## /) {
- sub(/^## /, "", line); print "" line "
"
- } else if (line ~ /^### /) {
- sub(/^### /, "", line); print "" line "
"
- } else if (line ~ /^#### /) {
- sub(/^#### /, "", line); print "" line "
"
- } else if (line ~ /^##### /) {
- sub(/^##### /, "", line); print "" line "
"
- } else if (line ~ /^###### /) {
- sub(/^###### /, "", line); print "" line "
"
+ tag = ""
+ if (line ~ /^# /) { tag = "h1"; sub(/^# /, "", line) }
+ else if (line ~ /^## /) { tag = "h2"; sub(/^## /, "", line) }
+ else if (line ~ /^### /) { tag = "h3"; sub(/^### /, "", line) }
+ else if (line ~ /^#### /) { tag = "h4"; sub(/^#### /, "", line) }
+ else if (line ~ /^##### /) { tag = "h5"; sub(/^##### /, "", line) }
+ else if (line ~ /^###### /) { tag = "h6"; sub(/^###### /, "", line) }
+
+ if (tag != "") {
+ id = strip_markdown(line)
+ if (enable_header_links == "true") {
+ print "<" tag " id=\"" id "\">" tag ">"
+ } else {
+ print "<" tag " id=\"" id "\">" line "" tag ">"
+ }
} else {
print line
}
diff --git a/kewt.sh b/kewt.sh
index 0034790..6c8f4b1 100755
--- a/kewt.sh
+++ b/kewt.sh
@@ -49,6 +49,7 @@ favicon = ""
generate_page_title = true
error_page = "not_found.html"
versioning = false
+enable_header_links = true
EOF
fi
@@ -282,6 +283,7 @@ favicon=""
generate_page_title="true"
error_page="not_found.html"
versioning="false"
+enable_header_links="true"
load_config() {
[ -f "$1" ] || return
@@ -322,6 +324,7 @@ load_config() {
generate_page_title) generate_page_title="$val" ;;
error_page) error_page="$val" ;;
versioning) versioning="$val" ;;
+ enable_header_links) enable_header_links="$val" ;;
esac
done < "$1"
}
@@ -435,6 +438,7 @@ copy_style_with_resolved_vars() {
render_markdown() {
file="$1"
+ is_home="$2"
local_template=$(find_closest "template.html" "$(dirname "$file")")
[ -z "$local_template" ] && local_template="$template"
@@ -485,20 +489,24 @@ render_markdown() {
page_title="$title"
if [ "$generate_page_title" = "true" ] && [ -n "$file" ] && [ -f "$file" ]; then
- first_heading=$(grep -m 1 '^# ' "$file" | sed 's/^# *//; s/ *$//')
- if [ -n "$first_heading" ]; then
- first_heading=$(echo "$first_heading" | sed -e 's/\[//g' -e 's/\]//g' -e 's/!//g' -e 's/\*//g' -e 's/_//g' -e 's/`//g' -e 's/([^)]*)//g' | sed 's/\\//g')
- page_title="$first_heading - $title"
+ if [ "$is_home" = "true" ] && [ -n "$home_name" ]; then
+ page_title="$home_name - $title"
else
- basename_no_ext=$(basename "$file" .md)
- if [ "$basename_no_ext" != "index" ] && [ "$basename_no_ext" != "404_gen" ]; then
- cap_basename=$(echo "$basename_no_ext" | awk '{print toupper(substr($0,1,1)) substr($0,2)}')
- page_title="$cap_basename - $title"
+ first_heading=$(grep -m 1 '^# ' "$file" | sed 's/^# *//; s/ *$//')
+ if [ -n "$first_heading" ]; then
+ first_heading=$(echo "$first_heading" | sed -e 's/\[//g' -e 's/\]//g' -e 's/!//g' -e 's/\*//g' -e 's/_//g' -e 's/`//g' -e 's/([^)]*)//g' | sed 's/\\//g')
+ page_title="$first_heading - $title"
+ else
+ basename_no_ext=$(basename "$file" .md)
+ if [ "$basename_no_ext" != "index" ] && [ "$basename_no_ext" != "404_gen" ]; then
+ cap_basename=$(echo "$basename_no_ext" | awk '{print toupper(substr($0,1,1)) substr($0,2)}')
+ page_title="$cap_basename - $title"
+ fi
fi
fi
fi
- MARKDOWN_SITE_ROOT="$src" MARKDOWN_FALLBACK_FILE="$script_dir/styles/$style.css" sh "$script_dir/markdown.sh" "$file" | awk -v title="$page_title" -v nav="$nav" -v footer="$footer" -v style_path="${style_path}${asset_version}" -v header_brand="$header_brand" -v head_extra="$head_extra" -f "$awk_dir/render_template.awk" "$local_template"
+ ENABLE_HEADER_LINKS="$enable_header_links" MARKDOWN_SITE_ROOT="$src" MARKDOWN_FALLBACK_FILE="$script_dir/styles/$style.css" sh "$script_dir/markdown.sh" "$file" | awk -v title="$page_title" -v nav="$nav" -v footer="$footer" -v style_path="${style_path}${asset_version}" -v header_brand="$header_brand" -v head_extra="$head_extra" -f "$awk_dir/render_template.awk" "$local_template"
}
echo "Building site from '$src' to '$out'..."
@@ -523,7 +531,8 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while
md_count=$(find "$dir" ! -name "$(basename "$dir")" -prune -name "*.md" | wc -l)
if [ "$md_count" -eq 1 ]; then
md_file=$(find "$dir" ! -name "$(basename "$dir")" -prune -name "*.md")
- render_markdown "$md_file" > "$out_dir/index.html"
+ is_home="false"; [ "$dir" = "$src" ] && is_home="true"
+ render_markdown "$md_file" "$is_home" > "$out_dir/index.html"
continue
fi
fi
@@ -546,7 +555,8 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type d -print" | sort | while
echo "- [$name]($name)" >> "$temp_index"
fi
done
- render_markdown "$temp_index" > "$out_dir/index.html"
+ is_home="false"; [ "$dir" = "$src" ] && is_home="true"
+ render_markdown "$temp_index" "$is_home" > "$out_dir/index.html"
rm "$temp_index"
fi
done
@@ -576,8 +586,9 @@ eval "find \"$src\" \( $IGNORE_ARGS \) -prune -o -type f -print" | sort | while
fi
if [ "${file%.md}" != "$file" ] && [ "$is_preserved" -eq 0 ]; then
+ is_home="false"; [ "$file" = "$src/index.md" ] && is_home="true"
out_file="$out/${rel_path%.md}.html"
- render_markdown "$file" > "$out_file"
+ render_markdown "$file" "$is_home" > "$out_file"
else
cp "$file" "$out/$rel_path"
fi
diff --git a/markdown.sh b/markdown.sh
index 7b2b61e..13a55f6 100755
--- a/markdown.sh
+++ b/markdown.sh
@@ -51,7 +51,7 @@ awk -f "$awk_dir/blockquote_to_admonition.awk" "$temp_file" > "$temp_file.tmp" &
awk -f "$awk_dir/fenced_code.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
awk -f "$awk_dir/indented_code.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
awk -f "$awk_dir/pipe_tables.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
-awk -f "$awk_dir/headers.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
+awk -v enable_header_links="$ENABLE_HEADER_LINKS" -f "$awk_dir/headers.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
awk -f "$awk_dir/lists.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
# Spacing
diff --git a/site.conf b/site.conf
deleted file mode 100644
index 8337095..0000000
--- a/site.conf
+++ /dev/null
@@ -1,16 +0,0 @@
-title = "kewt"
-style = "kewt"
-dir_indexes = true
-single_file_index = true
-flatten = false
-footer = "made with kewt"
-logo = ""
-display_logo = false
-display_title = true
-logo_as_favicon = true
-favicon = ""
-order = ""
-home_name = "Home"
-show_home_in_nav = true
-nav_links = ""
-nav_extra = ""
diff --git a/template.html b/template.html
deleted file mode 100644
index 2e95156..0000000
--- a/template.html
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
- {{TITLE}}
-
-
- {{HEAD_EXTRA}}
-
-
-
-
-
-
-
- {{CONTENT}}
-
-
-