Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aac9198878 | |||
| 99e1f5dd24 | |||
| 3970c6eb47 |
@@ -97,6 +97,23 @@ function read_file(path, out, line, rc) {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function read_file_or_render_md(path, ext, cmd, content, line, rc) {
|
||||||
|
content = ""
|
||||||
|
if (ext == "md") {
|
||||||
|
cmd = "sh \"" script_dir "/markdown.sh\" \"" path "\""
|
||||||
|
while ((cmd | getline line) > 0) {
|
||||||
|
content = content line "\n"
|
||||||
|
}
|
||||||
|
close(cmd)
|
||||||
|
} else {
|
||||||
|
while ((rc = getline line < path) > 0) {
|
||||||
|
content = content line "\n"
|
||||||
|
}
|
||||||
|
close(path)
|
||||||
|
}
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
function escape_html(s, t) {
|
function escape_html(s, t) {
|
||||||
t = s
|
t = s
|
||||||
gsub(/&/, "\\&", t)
|
gsub(/&/, "\\&", t)
|
||||||
@@ -189,7 +206,8 @@ function render_embed(src, alt, has_alt, force_inline, ext, local_path, conte
|
|||||||
if (force_inline && !is_global_url(src)) {
|
if (force_inline && !is_global_url(src)) {
|
||||||
local_path = resolve_local_path(src)
|
local_path = resolve_local_path(src)
|
||||||
if (local_path != "") {
|
if (local_path != "") {
|
||||||
content = read_file(local_path)
|
ext = ext_of(src)
|
||||||
|
content = read_file_or_render_md(local_path, ext)
|
||||||
if (content ~ /\n$/) sub(/\n$/, "", content)
|
if (content ~ /\n$/) sub(/\n$/, "", content)
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
@@ -217,7 +235,7 @@ function render_embed(src, alt, has_alt, force_inline, ext, local_path, conte
|
|||||||
if (is_inline_text_ext(ext)) {
|
if (is_inline_text_ext(ext)) {
|
||||||
local_path = resolve_local_path(src)
|
local_path = resolve_local_path(src)
|
||||||
if (local_path != "") {
|
if (local_path != "") {
|
||||||
content = read_file(local_path)
|
content = read_file_or_render_md(local_path, ext)
|
||||||
if (content ~ /\n$/) sub(/\n$/, "", content)
|
if (content ~ /\n$/) sub(/\n$/, "", content)
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
@@ -238,7 +256,7 @@ function render_typed_embed(etype, src, alt, has_alt, local_path, content) {
|
|||||||
if (!is_global_url(src)) {
|
if (!is_global_url(src)) {
|
||||||
local_path = resolve_local_path(src)
|
local_path = resolve_local_path(src)
|
||||||
if (local_path != "") {
|
if (local_path != "") {
|
||||||
content = read_file(local_path)
|
content = read_file_or_render_md(local_path, ext_of(src))
|
||||||
if (content ~ /\n$/) sub(/\n$/, "", content)
|
if (content ~ /\n$/) sub(/\n$/, "", content)
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ function mask_plain(s, t) {
|
|||||||
gsub(/\$/, "\034P8\034", t)
|
gsub(/\$/, "\034P8\034", t)
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
BEGIN { in_plain = 0 }
|
BEGIN { in_plain = 0; in_script_style = 0 }
|
||||||
{
|
{
|
||||||
line = $0
|
line = $0
|
||||||
out = ""
|
out = ""
|
||||||
@@ -48,5 +48,41 @@ BEGIN { in_plain = 0 }
|
|||||||
in_plain = 0
|
in_plain = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print out
|
tmp_line = out
|
||||||
|
out2 = ""
|
||||||
|
while (1) {
|
||||||
|
if (!in_script_style) {
|
||||||
|
pos_script = match(tolower(tmp_line), /<script([ >]|$)/)
|
||||||
|
script_start = RSTART; script_len = RLENGTH
|
||||||
|
pos_style = match(tolower(tmp_line), /<style([ >]|$)/)
|
||||||
|
style_start = RSTART; style_len = RLENGTH
|
||||||
|
|
||||||
|
if (pos_script == 0 && pos_style == 0) {
|
||||||
|
out2 = out2 tmp_line
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (pos_script > 0 && (pos_style == 0 || pos_script < pos_style)) {
|
||||||
|
out2 = out2 substr(tmp_line, 1, script_start + script_len - 1)
|
||||||
|
tmp_line = substr(tmp_line, script_start + script_len)
|
||||||
|
in_script_style = 1
|
||||||
|
end_tag = "</script>"
|
||||||
|
} else {
|
||||||
|
out2 = out2 substr(tmp_line, 1, style_start + style_len - 1)
|
||||||
|
tmp_line = substr(tmp_line, style_start + style_len)
|
||||||
|
in_script_style = 1
|
||||||
|
end_tag = "</style>"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pos_end = match(tolower(tmp_line), end_tag)
|
||||||
|
if (pos_end == 0) {
|
||||||
|
out2 = out2 mask_plain(tmp_line)
|
||||||
|
tmp_line = ""
|
||||||
|
break
|
||||||
|
}
|
||||||
|
out2 = out2 mask_plain(substr(tmp_line, 1, RSTART - 1)) substr(tmp_line, RSTART, RLENGTH)
|
||||||
|
tmp_line = substr(tmp_line, RSTART + RLENGTH)
|
||||||
|
in_script_style = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print out2
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ BEGIN {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
if ($0 ~ /^<pre>/) in_pre = 1
|
if ($0 ~ /<pre>/) in_pre = 1
|
||||||
|
|
||||||
if (in_pre) {
|
if (in_pre) {
|
||||||
if (in_p) { print "</p>"; in_p = 0 }
|
if (in_p) { print "</p>"; in_p = 0 }
|
||||||
@@ -13,7 +13,16 @@ BEGIN {
|
|||||||
next
|
next
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($0 ~ /^<\/?(div|table|p|[ou]l|h[1-6]|[bh]r|blockquote|li|hr|section|article|nav|aside|header|footer|dl|dt|dd)/) {
|
if ($0 ~ /^<\/?(div|table|p|[ou]l|h[1-6]|[bh]r|blockquote|li|hr|section|article|nav|aside|header|footer|dl|dt|dd|script|style|iframe|details|summary|figure|figcaption|audio|video|picture)/) {
|
||||||
|
if (in_p) {
|
||||||
|
print "</p>"
|
||||||
|
in_p = 0
|
||||||
|
}
|
||||||
|
print
|
||||||
|
next
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($0 ~ /^[\t ]*!([a-zA-Z])?\[[^\]]*\](\([^)]*\))?[\t ]*$/ || $0 ~ /^[\t ]*!!?\[[^\]]*\](\([^)]*\))?[\t ]*$/) {
|
||||||
if (in_p) {
|
if (in_p) {
|
||||||
print "</p>"
|
print "</p>"
|
||||||
in_p = 0
|
in_p = 0
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ BEGIN {
|
|||||||
style_path = ENVIRON["AWK_STYLE_PATH"]
|
style_path = ENVIRON["AWK_STYLE_PATH"]
|
||||||
head_extra = ENVIRON["AWK_HEAD_EXTRA"]
|
head_extra = ENVIRON["AWK_HEAD_EXTRA"]
|
||||||
header_brand = ENVIRON["AWK_HEADER_BRAND"]
|
header_brand = ENVIRON["AWK_HEADER_BRAND"]
|
||||||
|
lang = ENVIRON["AWK_LANG"]
|
||||||
if (current_url != "") {
|
if (current_url != "") {
|
||||||
nav = replace_all(nav, "href=\"" current_url "\"", "href=\"" current_url "\" class=\"current-page\"")
|
nav = replace_all(nav, "href=\"" current_url "\"", "href=\"" current_url "\" class=\"current-page\"")
|
||||||
}
|
}
|
||||||
@@ -24,6 +25,7 @@ BEGIN {
|
|||||||
{
|
{
|
||||||
line = $0
|
line = $0
|
||||||
line = replace_all(line, "{{TITLE}}", title)
|
line = replace_all(line, "{{TITLE}}", title)
|
||||||
|
line = replace_all(line, "{{LANG}}", lang)
|
||||||
line = replace_all(line, "{{NAV}}", nav)
|
line = replace_all(line, "{{NAV}}", nav)
|
||||||
line = replace_all(line, "{{FOOTER}}", footer)
|
line = replace_all(line, "{{FOOTER}}", footer)
|
||||||
line = replace_all(line, "{{CSS}}", style_path)
|
line = replace_all(line, "{{CSS}}", style_path)
|
||||||
|
|||||||
14
kewt.sh
14
kewt.sh
@@ -40,6 +40,8 @@ trap 'exit 0' HUP INT TERM
|
|||||||
|
|
||||||
DEFAULT_CONF='title = "kewt"
|
DEFAULT_CONF='title = "kewt"
|
||||||
style = "kewt"
|
style = "kewt"
|
||||||
|
lang = "en"
|
||||||
|
draft_by_default = false
|
||||||
dir_indexes = true
|
dir_indexes = true
|
||||||
single_file_index = true
|
single_file_index = true
|
||||||
flatten = false
|
flatten = false
|
||||||
@@ -66,7 +68,7 @@ posts_per_page = 12
|
|||||||
custom_admonitions = ""'
|
custom_admonitions = ""'
|
||||||
|
|
||||||
DEFAULT_TMPL='<!doctype html>
|
DEFAULT_TMPL='<!doctype html>
|
||||||
<html>
|
<html lang="{{LANG}}">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
@@ -145,9 +147,9 @@ create_new_post() {
|
|||||||
|
|
||||||
post_date_val="$(date "+%Y-%m-%d %H:%M")"
|
post_date_val="$(date "+%Y-%m-%d %H:%M")"
|
||||||
if [ -n "$post_user_title" ]; then
|
if [ -n "$post_user_title" ]; then
|
||||||
printf -- '---\ntitle = "%s"\ndate = "%s"\ndraft = false\n---\n# %s\n' "$post_user_title" "$post_date_val" "$post_user_title" > "$file_path"
|
printf -- '---\ntitle = "%s"\ndate = "%s"\ndraft = %s\n---\n# %s\n' "$post_user_title" "$post_date_val" "$draft_by_default" "$post_user_title" > "$file_path"
|
||||||
else
|
else
|
||||||
printf -- '---\ndate = "%s"\ndraft = false\n---\n' "$post_date_val" > "$file_path"
|
printf -- '---\ndate = "%s"\ndraft = %s\n---\n' "$post_date_val" "$draft_by_default" > "$file_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Created new post at '$file_path'."
|
echo "Created new post at '$file_path'."
|
||||||
@@ -420,6 +422,8 @@ generate_nav() {
|
|||||||
|
|
||||||
title="kewt"
|
title="kewt"
|
||||||
style="kewt"
|
style="kewt"
|
||||||
|
lang="en"
|
||||||
|
draft_by_default="false"
|
||||||
footer="made with <a href=\"https://kewt.krzak.org\">kewt</a>"
|
footer="made with <a href=\"https://kewt.krzak.org\">kewt</a>"
|
||||||
dir_indexes="true"
|
dir_indexes="true"
|
||||||
single_file_index="true"
|
single_file_index="true"
|
||||||
@@ -498,6 +502,8 @@ load_config() {
|
|||||||
posts_dir) posts_dir="${val#/}" ;;
|
posts_dir) posts_dir="${val#/}" ;;
|
||||||
posts_per_page) posts_per_page="$val" ;;
|
posts_per_page) posts_per_page="$val" ;;
|
||||||
custom_admonitions) custom_admonitions="$val" ;;
|
custom_admonitions) custom_admonitions="$val" ;;
|
||||||
|
lang) lang="$val" ;;
|
||||||
|
draft_by_default) draft_by_default="$val" ;;
|
||||||
esac
|
esac
|
||||||
done < "$1"
|
done < "$1"
|
||||||
}
|
}
|
||||||
@@ -757,7 +763,7 @@ render_markdown() {
|
|||||||
head_extra="$head_extra_og"
|
head_extra="$head_extra_og"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ENABLE_HEADER_LINKS="$enable_header_links" CUSTOM_ADMONITIONS="$custom_admonitions" MARKDOWN_SITE_ROOT="$src" MARKDOWN_FALLBACK_FILE="$script_dir/styles/$style.css" sh "$script_dir/markdown.sh" "$content_file" | AWK_CURRENT_URL="$current_url" AWK_TITLE="$page_title" AWK_NAV="$nav" AWK_FOOTER="$footer" AWK_STYLE_PATH="${style_path}${asset_version}" AWK_HEADER_BRAND="$header_brand" AWK_HEAD_EXTRA="$head_extra" awk -f "$awk_dir/render_template.awk" "$local_template"
|
ENABLE_HEADER_LINKS="$enable_header_links" CUSTOM_ADMONITIONS="$custom_admonitions" MARKDOWN_SITE_ROOT="$src" MARKDOWN_FALLBACK_FILE="$script_dir/styles/$style.css" sh "$script_dir/markdown.sh" "$content_file" | AWK_LANG="$lang" AWK_CURRENT_URL="$current_url" AWK_TITLE="$page_title" AWK_NAV="$nav" AWK_FOOTER="$footer" AWK_STYLE_PATH="${style_path}${asset_version}" AWK_HEADER_BRAND="$header_brand" AWK_HEAD_EXTRA="$head_extra" awk -f "$awk_dir/render_template.awk" "$local_template"
|
||||||
}
|
}
|
||||||
|
|
||||||
needs_rebuild() {
|
needs_rebuild() {
|
||||||
|
|||||||
@@ -77,5 +77,5 @@ awk -f "$awk_dir/paragraphs.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_fi
|
|||||||
# Inline styles
|
# Inline styles
|
||||||
awk -f "$awk_dir/emoji.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
|
awk -f "$awk_dir/emoji.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
|
||||||
awk -f "$awk_dir/markdown_inline.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
|
awk -f "$awk_dir/markdown_inline.awk" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file"
|
||||||
awk -v input_file="$1" -v site_root="$MARKDOWN_SITE_ROOT" -v fallback_file="$MARKDOWN_FALLBACK_FILE" -f "$awk_dir/markdown_embed.awk" "$temp_file"
|
awk -v input_file="$1" -v site_root="$MARKDOWN_SITE_ROOT" -v fallback_file="$MARKDOWN_FALLBACK_FILE" -v script_dir="$script_dir" -f "$awk_dir/markdown_embed.awk" "$temp_file"
|
||||||
rm "$temp_file"
|
rm "$temp_file"
|
||||||
|
|||||||
Reference in New Issue
Block a user