This commit is contained in:
bel
2021-09-14 06:29:17 -06:00
commit a71c585675
36 changed files with 700 additions and 0 deletions

4
gollum/.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
mnt
**.sw*
**/*.sw*
*.sw*

3
gollum/.gitignore vendored Executable file
View File

@@ -0,0 +1,3 @@
mnt/
*.sw*
goftp

15
gollum/Dockerfile Executable file
View File

@@ -0,0 +1,15 @@
FROM frolvlad/alpine-glibc:alpine-3.9_glibc-2.28
RUN apk update; \
apk add --no-cache ruby dcron bash cmake ruby-dev make icu-dev gcc libc-dev zlib-dev g++ openssl openssl-dev git; \
gem install rdoc || true; \
gem install github-linguist gollum org-ruby thin etc || true; \
gem install rdoc || true; \
apk del gcc g++ libc-dev zlib-dev openssl openssl-dev cmake make;
RUN gem install github-markup commonmarker || true;
# TODO what gems needed to render tables with markdown
ENV PORT=8080
CMD []
WORKDIR /wiki
COPY . /opt/
ENTRYPOINT ["/bin/bash", "/opt/entrypoint.sh"]

63
gollum/build_and_run.sh Executable file
View File

@@ -0,0 +1,63 @@
#! /bin/bash
set -e
set -u
cd "$(dirname "${BASH_SOURCE[0]}")"
dir="$PWD"
if [ ! -e ./goftp ]; then
pushd $GOPATH/src/local/goftp
CGO_ENABLED=0 GOOS=linux go build -o "$dir/goftp" -a -installsuffix cgo
popd
fi
img_tag="${1:-"dev:dev"}"
docker build -t "$img_tag" .
mkdir -p $PWD/mnt
sudo chmod -R 777 $PWD/mnt
rm -rf $PWD/mnt/this
mkdir -p $PWD/mnt/this/is\ a/test/path
rm -f $PWD/mnt/this/{_Header.md,file.md}
echo '# hello' > $PWD/mnt/this/file.md
pushd $PWD/mnt
if [ ! -e Home.md ]; then
echo 'immediate pages
<<ImmediatePages()>>
immediate pages from /this/
<<ImmediatePages("/this/")>>
path segments
<<PathSegments()>>
drop down
<<DropDown("title", "hidden")>>
h1, h2, h3, para
# Hello
## h2
### h3
paragraph
' > Home.md
fi
popd
function clean() {
docker rm -f gollum-dev
}
trap clean EXIT
if [ -z "${BUILD:-""}" ]; then
docker run --rm -it \
--name gollum-dev \
-e PORT=38080 \
-p 38180:38080 \
-p 38181:38081 \
-v $PWD/mnt:/wiki \
$img_tag
fi

72
gollum/config.rb Executable file
View File

@@ -0,0 +1,72 @@
=begin
This file can be used to (e.g.):
- alter certain inner parts of Gollum,
- extend it with your stuff.
It is especially useful for customizing supported formats/markups. For more information and examples:
- https://github.com/gollum/gollum#config-file
=end
module Gollum
class Macro
class ImmediatePages < Gollum::Macro
def render(toc_root_path = nil, max_depth = 1, min_depth = 0)
if toc_root_path == nil
if @page.path == "Home.md"
toc_root_path = ""
else
toc_root_path = @page.path.sub(/\.[a-z]+$/,'/')
end
end
if toc_root_path.start_with?("/")
toc_root_path[0] = ''
end
if toc_root_path != "" and not toc_root_path.end_with?("/")
toc_root_path << '/'
end
if @wiki.pages.size > 0
list_items = @wiki.pages.map do |page|
if @page.url_path != page.url_path and page.url_path.start_with?(toc_root_path)
path_display = page.url_path_display.sub(toc_root_path.gsub("-", " "), "").sub(/^\//,'')
depth = path_display.count("/")
if depth.to_i < max_depth.to_i and depth.to_i >= min_depth.to_i
" <li><a href=\"/#{page.url_path}\">#{path_display}</a></li>"
end
end
end
result = "<ul>#{list_items.join}</ul>"
end
title = toc_root_path
"<div class=\"toc\"><div class=\"toc-title\">#{title}</div>#{result}</div>"
end
end
class PathSegments < Gollum::Macro
def render(append = "")
segments = @page.path.split('/')
segments = segments.first(segments.size - 1)
if append != ""
segments << append
end
full = ""
list_items = segments.map do |segment|
full = "#{full}/#{segment}"
" / <a href=\"#{full}\">#{segment}</a>"
end
list_items.insert(0, " / <a href=\"/Home\">Home</a>")
list_items << " / <a id='last_segment' onload='load_segment();' href='#'></a>"
"<div>#{list_items.join}</div>"
end
end
class DropDown < Gollum::Macro
def render(summary, detail)
"<details><summary>#{summary}</summary><div class=\"toc\">#{detail}</div></details"
end
end
class ImgDropDown < Gollum::Macro
def render(img_link, title = "Image")
"<details><summary>#{title}</summary><div class=\"img-drop-down\"><img src=\"#{img_link}\"/></div></details"
end
end
end
end

67
gollum/custom.css Executable file
View File

@@ -0,0 +1,67 @@
#head
> .actions
> .minibutton:nth-last-child(-n+2)
, #head
> .actions
> .minibutton:nth-child(6)
, #head
> .actions
> .minibutton:nth-child(4)
{
display: none;
}
body
{
background-color: #222;
-webkit-filter: invert(85%);
filter: invert(85%);
}
img
{
-webkit-filter: invert(100%);
filter: invert(100%);
}
.img-drop-down
{
width: 100%;
}
.img-drop-down
> img
{
text-align: center;
margin: 0 auto;
padding: 1em 0;
max-width: 100%;
max-height: 400px;
display: block;
}
.markdown-body
h1
{
border-top: 1px solid #ddd;
padding-top: 10px;
}
#head
> h1
{
/*display: none;*/
width: 100%;
}
summary
> h1
, summary
> h2
, summary
> h3
, summary
> h4
{
display: inline-block;
}

13
gollum/custom.js Executable file
View File

@@ -0,0 +1,13 @@
function load_segment() {
var elem = document.getElementById("last_segment")
if (elem) {
var arr = window.location.href.split('/')
elem.innerHTML = arr[arr.length-1]
elem.setAttribute("href", window.location.href.split('#')[0])
} else {
setTimeout(function() {
load_segment()
}, 50)
}
}
load_segment()

27
gollum/entrypoint.sh Executable file
View File

@@ -0,0 +1,27 @@
#! /bin/bash
function main() {
set -e
cd /wiki
git init || true
crontab /opt/routine.cron
bash /opt/index.sh
/opt/goftp \
-port $((PORT+1)) \
-root /wiki/uploads-ftp \
& gollum \
--port $PORT \
--no-live-preview \
--config /opt/config.rb \
--collapse-tree \
--allow-uploads=dir \
--css \
--js \
"$@"
}
if [ "$0" == "${BASH_SOURCE[0]}" ]; then
main "$@"
fi

88
gollum/index.sh Executable file
View File

@@ -0,0 +1,88 @@
#! /bin/bash
function main() {
set -e
fill_missing_files
format_files
init_git
}
function fill_missing_files() {
pushd "${1:-/wiki}" > /dev/null 2>&1
fill_if_missing ./Home.md
fill_if_missing ./_Header.md
find ./* -type d | while read -r i; do
i="${i%/}"
fill_if_missing "$i.md"
fill_if_missing "$i/_Header.md"
done
rm -f .git/hooks/pre-commit || true
for i in .git/hooks/pre-commit custom.css custom.js; do
fill_if_missing ./$i "$(cat /opt/${i##*/})"
done
mkdir -p ./uploads-ftp
cp /opt/favicon.ico . || true
popd > /dev/null 2>&1
}
function format_files() {
pushd ${1:-/wiki} > /dev/null 2>&1
local patterns=('^[0-9][0-9]*\. *' ' 1. ')
local f="/tmp/switch"
find . -type f -name "*.md" | grep -v '\/_[^\/]*.md' | while read -r path; do
for ((i=0; i<${#patterns[@]}; i+=2)); do
local from="${patterns[i]}"
local to="${patterns[i+1]}"
if [ -n "$(grep "${from// /.}" "$path")" ]; then
cat "$path" \
| sed "s/$from/$to/g" \
> "$f"
cp "$f" "$path"
fi
done
done
rm -f "$f"
popd > /dev/null 2>&1
}
function init_git() {
pushd ${1:-/wiki} > /dev/null 2>&1
git config user.email bel@bel.bel
git config user.name bel
git add -A :/
if [ "${JUST_ADD:-""}" != "true" ]; then
JUST_ADD=true git commit --author="auto <>" -m "routine" || true
fi
popd > /dev/null 2>&1
}
function fill_if_missing() {
local relative_path="$1"
shift
mkdir -p "$(dirname "$relative_path")"
local full_path="$(printf "%s/%s" \
"$(realpath \
"$(dirname "$relative_path")" \
)" \
"$(basename "$relative_path")" \
)"
if [ ! -e "$full_path" ]; then
if [ "$#" -gt 0 ]; then
echo "$@" > "$full_path"
elif [[ "$relative_path" == *"_Header.md" ]]; then
echo "<<PathSegments()>>" > "$full_path"
else
echo "<<ImmediatePages()>>" > "$full_path"
fi
fi
chmod +x "$full_path"
}
if [ "$0" == "${BASH_SOURCE[0]}" ]; then
main "$@"
fi

5
gollum/pre-commit Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
echo DO INDEX.sh;
git status;
JUST_ADD=true bash /opt/index.sh || true;

1
gollum/review Executable file
View File

@@ -0,0 +1 @@
ruby scripting is fantastic and fun, but tags/metadata are hard

1
gollum/routine.cron Executable file
View File

@@ -0,0 +1 @@
0 0/2 * * * /bin/bash /opt/index.sh