Compare commits
5 Commits
660cd3bd5b
...
b2e1d87b21
Author | SHA1 | Date |
---|---|---|
hedy | b2e1d87b21 | |
hedy | 346cc5bb85 | |
hedy | bdbe083640 | |
hedy | f822e1444e | |
hedy | e7b575b071 |
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
59
bin/post
59
bin/post
|
@ -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"
|
||||
|
|
|
@ -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")
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
{{ define "content" -}}
|
||||
{{ readFile (replace (replace $.File.Path ".md" ".gmi") ".html" ".gmi") | safeHTML }}
|
||||
|
||||
{{ partial "posts.gmi" . }}
|
||||
{{ partial "processed-content.gmi" . }}
|
||||
|
||||
--
|
||||
{{- end }}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
{{ define "main" }}
|
||||
{{ .Content }}
|
||||
{{ partial "posts.html" . }}
|
||||
{{ end }}
|
||||
|
|
|
@ -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 -}}
|
||||
|
|
|
@ -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 -}}
|
|
@ -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:
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{{ partial "posts.gmi" .Page }}
|
|
@ -0,0 +1 @@
|
|||
{{ partial "posts.html" .Page }}
|
Loading…
Reference in New Issue