Compare commits

...

5 Commits

Author SHA1 Message Date
hedy b2e1d87b21
Add webrings and place posts list in any position for index pages 2024-04-11 10:09:11 +08:00
hedy 346cc5bb85
Update archetypes 2024-04-11 10:07:51 +08:00
hedy bdbe083640
Use dirs for all posts 2024-04-11 09:03:07 +08:00
hedy f822e1444e
Extract gmi processed content into its own partial 2024-04-11 08:51:07 +08:00
hedy e7b575b071
Apply updates to gemini version of synhi post 2024-04-11 08:50:44 +08:00
27 changed files with 156 additions and 74 deletions

View File

View File

@ -1,7 +1,11 @@
---
title: "{{ slicestr (replace .Name "-" " ") 11 | title }}"
date: {{ .Date }}
{{ $title := slicestr (replace .Name "-" " ") 11 -}}
title: {{ $title | title }}
description: {{ strings.FirstUpper $title }}
highlight: false
draft: true
date: {{ .Date }}
outputs:
- html
- gemtext

View File

@ -20,7 +20,7 @@ def log(fn):
if DRY_RUN:
print("would", end=" ")
print(fn.__name__.replace('_', ' '),
'->'.join(p.removeprefix(GMI_DEST) for p in args))
' -> '.join(p.removeprefix(GMI_DEST) for p in args))
if not DRY_RUN:
fn(*args)
return inner

41
bin/lib Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env bash
BLUE=$(tput setaf 12)
RED=$(tput setaf 9)
GREEN=$(tput setaf 10)
RESET=$(tput sgr0)
blue() {
echo ${BLUE}"$@"${RESET}
}
yesno () {
# yesno "prompt" "y"
# default
prompt="$1"
if [[ "$2" == n ]]; then
prompt="$prompt"' [y/N] '
else
if [[ "$2" == y ]]; then
prompt="$prompt"' [Y/n] '
else
prompt="$prompt"' [y/n] '
fi
fi
read -p "$prompt"
REPLY=$(echo "$REPLY" | tr A-Z a-z)
if [[ -z "$REPLY" ]]; then
REPLY="$2" # default
fi
if [[ "$REPLY" =~ ^y$ ]]; then
echo y; return 0
else
if [[ "$REPLY" =~ ^n$ ]]; then
echo n; return 1
fi
echo ${RED}Invalid option!${RESET} > /dev/stderr
yesno "$@"
fi
}

View File

@ -1,56 +1,9 @@
#!/usr/bin/env bash
BLUE=$(tput setaf 12)
RED=$(tput setaf 9)
GREEN=$(tput setaf 10)
RESET=$(tput sgr0)
blue() {
echo ${BLUE}"$@"${RESET}
}
yesno () {
prompt="$1"
if [[ "$2" == n ]]; then
prompt="$prompt"' [y/N] '
else
if [[ "$2" == y ]]; then
prompt="$prompt"' [Y/n] '
else
prompt="$prompt"' [y/n] '
fi
fi
read -p "$prompt"
REPLY=$(echo "$REPLY" | tr A-Z a-z)
if [[ -z "$REPLY" ]]; then
REPLY="$2" # default
fi
if [[ "$REPLY" =~ ^y$ ]]; then
echo y; return 0
else
if [[ "$REPLY" =~ ^n$ ]]; then
echo n; return 1
fi
echo ${RED}Invalid option!${RESET} > /dev/stderr
yesno "$@"
fi
}
read -p "$(blue slug:\ )" filename
filename=posts/$(date "+%Y-%m-%d")-"$filename".md
created=$(hugo new "$filename" | sed 's/.*"\(.*\)".*/\1/')
# do I just suck at shell scripting or is shell scripting so f'ed up that it
# just refuses to work??
# echo "$created"
#
# if ! yesno "$(blue 'draft?')" y; then
# # Not using in-place here because of MacOS vs GNU sed mess
# cat "$created" | sed 's/draft: true/draft: false/' > $created
# fi
# Create a new post with hugo given slug, and open it with an editor
if yesno "$(blue edit?)" y; then
"${EDITOR:-vim}" "$created"
fi
read -p "slug: " filename
filename=posts/$(date "+%Y-%m-%d")-"$(echo $filename | tr ' ' '-' )"
created=$(hugo new "$filename/index.md" | sed 's/.*"\(.*\)".*/\1/')
touch "$(dirname $created)/index.gmi"
"${EDITOR:-vim}" "$created"

59
bin/post-dirs.py Normal file
View File

@ -0,0 +1,59 @@
#!/usr/bin/env python3
# convert content/posts/*.{gmi,md} -> content/posts/*/index.{gmi,md}
# 2024 - hedy - initial implementation with logging
# post process gemini output
import os
import shutil
import sys
from functools import wraps
from glob import glob
PREFIX = os.environ['PREFIX']
DRY_RUN = len(sys.argv) > 2 and \
sys.argv[1].lower() in ('n', '-n', '--dry-run', 'wtf', 'f')
def log(fn):
@wraps(fn)
def inner(*args):
if DRY_RUN:
print("would", end=" ")
print(fn.__name__.replace('_', ' '),
' -> '.join(p.removeprefix(PREFIX) for p in args))
if not DRY_RUN:
fn(*args)
return inner
@log
def remove(p: str):
if os.path.isdir(p):
os.rmdir(p)
else:
os.remove(p)
@log
def FORCE_remove_dir(p: str):
shutil.rmtree(p, ignore_errors=True)
@log
def rename(f: str, t: str):
os.rename(f, t)
@log
def mkdir(d: str):
os.makedirs(d, exist_ok=True)
################################################################
for file in glob(PREFIX+"/????-??-??-*.md"):
basename = file.split("/")[-1].removesuffix(".md")
dir = f"{PREFIX}/{basename}"
mkdir(dir)
rename(file, f"{dir}/index.md")
for file in glob(PREFIX+"/????-??-??-*.gmi"):
basename = file.split("/")[-1].removesuffix(".gmi")
dir = f"{PREFIX}/{basename}"
rename(file, f"{dir}/index.gmi")

View File

@ -44,6 +44,24 @@ All public projects:
=> https://sr.ht/~hedy
=> https://github.com/hedyhli
{{< posts-list >}}
## Orbits (webrings)
=> gemini://raek.se/orbits/space-elevator/ The Space Elevator
=> gemini://raek.se/orbits/space-elevator/prev?home.hedy.dev Previous
=> gemini://raek.se/orbits/space-elevator/random?home.hedy.dev Random
=> gemini://raek.se/orbits/space-elevator/next?home.hedy.dev Next
=> gemini://tilde.team/~khuxkm/leo/ LEO Orbit
=> gemini://tilde.team/~khuxkm/leo/prev.cgi?home.hedy.dev Previous
=> gemini://tilde.team/~khuxkm/leo/rand.cgi?home.hedy.dev Random
=> gemini://tilde.team/~khuxkm/leo/next.cgi?home.hedy.dev Next
=> gemini://fediring.net/ Fediring
=> gemini://fediring.net/previous/@hedy@tilde.zone Previous
=> gemini://fediring.net/random Random
=> gemini://fediring.net/next/@hedy@tilde.zone Next
## Useful links to outer space

View File

@ -27,3 +27,11 @@ Alternate versions of this site are available on
[gemini://](https://gemini.circumlunar.space) (linked at the footer),
[spartan://](https://portal.mozz.us/gemini/spartan.mozz.us), and gopher.
{{% posts-list %}}
## Webrings
[Fediring](https://fediring.net) ·
[[← Prev](https://fediring.net/previous?host=home.hedy.dev)]
[[Random](https://fediring.net/random)]
[[Next →](https://fediring.net/next?host=home.hedy.dev)]

View File

@ -1,4 +1,4 @@
Hugo uses chroma[1] as its syntax highlighter, and it's mostly compatible with pygments. All you basically need for having your code highlighted is to let chroma put the syntax classes in the generated HTML, for the correct language, and then make sure you have corresponding CSS for those classes.
Hugo uses chroma[1] as its syntax highlighter. All you basically need for having your code highlighted is to let chroma put the syntax classes in the generated HTML, for the correct language, and then make sure you have corresponding CSS for those classes.
=> https://github.com/alecthomas/chroma 1: https://github.com/alecthomas/chroma

View File

@ -1,7 +1,5 @@
{{ define "content" -}}
{{ readFile (replace (replace $.File.Path ".md" ".gmi") ".html" ".gmi") | safeHTML }}
{{ partial "posts.gmi" . }}
{{ partial "processed-content.gmi" . }}
--
{{- end }}

View File

@ -1,4 +1,3 @@
{{ define "main" }}
{{ .Content }}
{{ partial "posts.html" . }}
{{ end }}

View File

@ -12,4 +12,4 @@
{{- if .OutputFormats.Get "gemtext" }}
=> {{replace (replace .RelPermalink "/gemini" "" 1) "/index.gmi" ".gmi" 1}} {{ .Date.Format "2006-01-02" }} · {{.Title | safeHTML}}{{ end }}
{{ .Description }}
{{ end }}
{{ end -}}

View File

@ -0,0 +1,11 @@
{{- /*
* https://discourse.gohugo.io/t/using-renderstring-to-expand-shortcodes/40994/7
* support for using shortcodes in gemtext whilst having content as raw text.
*/ -}}
{{- $content := printf "~~~\n\n%s\n~~~" (trim (readFile (replace $.File.Path ".md" ".gmi")) "\n" | safeHTML) | .Page.RenderString | htmlUnescape }}
{{- $lines := split $content "\n" }}
{{- range $i, $_ := $lines }}
{{- if and $i (ne $i (sub (len $lines) 1)) }}
{{ . }}
{{- end -}}
{{- end -}}

View File

@ -18,18 +18,7 @@ Tag:
{{- if $index -}}, {{ end -}}{{ if (not $index) }}{{printf " "}}{{end}}{{ $tag | urlize }}{{- end -}}{{- end }}
{{- end }}
--
{{- /*
* https://discourse.gohugo.io/t/using-renderstring-to-expand-shortcodes/40994/7
* support for using shortcodes in gemtext whilst having content as raw text.
*/ -}}
{{- $content := printf "~~~\n%s~~~" (trim (readFile (replace $.File.Path ".md" ".gmi")) "\n" | safeHTML) | .Page.RenderString | htmlUnescape }}
{{- $lines := split $content "\n" }}
{{- range $i, $_ := $lines }}
{{- if and $i (ne $i (sub (len $lines) 1)) }}
{{ . }}
{{- end -}}
{{- end -}}
{{ partial "processed-content.gmi" . }}
--
Questions/comments:

View File

@ -0,0 +1 @@
{{ partial "posts.gmi" .Page }}

View File

@ -0,0 +1 @@
{{ partial "posts.html" .Page }}