~zenomat/tinywiki

ce56603385c2e5084ab1f31add79f30ec6a88e1c — zeno 3 months ago
inital push
5 files changed, 330 insertions(+), 0 deletions(-)

A README.md
A build.sh
A run
A style.css
A template.html
A  => README.md +16 -0
@@ 1,16 @@
Tinywiki is a simple bash script, which converts a folder into a static html wiki.

# Features
- Table of contents insertion with [[toc]]
- katex math
- subfolders
- pandoc frontmatter
- maybe some others I am forgetting
- beautiful styling

- this is in a super rough state at the moment
- improvments will come till it is in a state where:
	- you git clone the repo
	- issue one command
	- have a static html wiki
- **Requires bash**

A  => build.sh +65 -0
@@ 1,65 @@
#!/bin/sh -e

if [[ "$1" == 'pdf' ]]; then
	outdir="$HOME/code/tinywiki/deploy_notes/public_pdf"
elif [[ "$1" == 'html' ]]; then
	outdir="$HOME/code/tinywiki/deploy_notes/public_html"
fi

if [[ "$1" == 'pdf' ]]; then
	mkdir -p $outdir/tmp
	outfiles=()
	for file in "${@:2}"; do
		echo "Converting $file"
		pandoc  -f markdown+hard_line_breaks "$file" -o $outdir/tmp/$(basename $file | cut -f 1 -d '.').pdf
		outfiles+=($(basename $file | cut -f 1 -d '.').pdf)
	done
	cd $outdir/tmp
	echo "Uniting pdf"
	pdfunite ${outfiles[*]} $outdir/notes.pdf
	cd $outdir
	rm -rf $outdir/tmp
	echo DONE
fi

if [[ "$1" == 'html' ]]; then
	mkdir -p "$outdir/tmp"
	mkdir -p "$outdir/assets"
	cp ./deploy_notes/template.html ./deploy_notes/style.css "$outdir/assets"

	for file in "${@:2}"; do
		path=$(dirname $file)
		name=$(basename $file | cut -f 1 -d '.')
		title=$(grep title "$file" | cut -d":" -f 2- | cut -b 2-)
		if [ "$title" = "" ]; then
			title="$name"
		fi
		echo "["$title"]("$path/$name".html)" >> "$outdir/tmp/toc.md"
	done

	for file in "${@:2}"; do
		echo "Converting $file"
		file=$(echo $file | cut -c 3-)
		path=$(dirname $file)
		name=$(basename $file | cut -f 1 -d '.')
		path_to_root=$(realpath --relative-to="$outdir/$path" "$outdir")
		escaped_path_to_root=$(printf '%s\n' "$path_to_root" | sed -e 's/[\/&]/\\&/g')
		cp $outdir/../../$file $outdir/tmp
		awk -v S="$(cat $outdir/tmp/toc.md)" '/\[\[toc\]\]/{$0=S}1' "$file" > "$outdir/tmp/$name.md"
		grep -Po '\[.+\]\((?!https?:\/\/).*(?<!\.html|\.png|\.svg|\.jpg)\)' "$outdir/../../$file" | while read match; do
			clean_match=$(echo $match | awk -F '(' ' {{print $2}} ' | cut -f 1 -d ')')
			link=$clean_match.html
			escaped_match=$(printf '%s\n' "$clean_match" | sed -e 's/[\/&]/\\&/g')
			escaped_link=$(printf '%s\n' "$link" | sed -e 's/[\/&]/\\&/g')
			sed -ie "s/$escaped_match/$escaped_link/" "$outdir/tmp/$name.md"
		done
		mkdir -p $outdir/$path
		pandoc -s --template="$outdir/assets/template.html" -V home="$path_to_root/index.html" --css=$path_to_root/assets/style.css --highlight-style breezedark -f markdown+hard_line_breaks --katex $outdir/tmp/"$name".md -o $outdir/$path/$name.html
		sed -i "s/https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/KaTeX\/0.11.1\/katex.min.css/$escaped_path_to_root\/assets\/css\/katex.min.css/g" "$outdir/$path/$name.html"
		sed -i "s/https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/KaTeX\/0.11.1\/katex.min.js/$escaped_path_to_root\/assets\/js\/katex.min.js/g" "$outdir/$path/$name.html"
	done
	cd ..
	cat $outdir/tmp/toc.md
	rm -rf $outdir/tmp
	echo DONE
fi

A  => run +9 -0
@@ 1,9 @@
#!/bin/sh

cd $HOME/code/tinywiki
if [ "$1" == "html" ]; then
	find . -name "*.md" -exec deploy_notes/build.sh html '{}' +;
elif [ "$1" == "pdf" ]; then
	find . -name "*.md" -exec deploy_notes/build.sh pdf '{}' +;
fi
rm -rf ~/docs/notes_html

A  => style.css +172 -0
@@ 1,172 @@
:root {
    --bg-col: #1c1e26;
    --fg-col: #ffffff;
    --accent: #e93c58;
    --sec-accent: #9a9a9a;
}

* {
  box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 20px;
    background-color: var(--bg-col);
    color: var(--fg-col);
    font-family: sans-serif;
    font-size: 20px;
    line-height: 1.5;
}

a, a:visited {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--sec-accent);
}

h1, h2, h3, h4, h5, h6 {
    color: var(--accent);
    font-weight: 400;
	text-align: center;
}

h1 {
	font-size: 2.25rem;
}

h2 {
	font-size: 1.85rem;
  	margin-top: 3rem;
}

h3 {
	font-size: 1.55rem;
  margin-top: 3rem;
}

h4 {
	font-size: 1.25rem;
}

h5 {
	font-size: 1.15rem;
}

h6 {
	font-size: .9rem;
}

hr {
    margin-top: 15px;
    margin-bottom: 15px;
}

hr {
    color: #ffffff;
}

p.title {
    color: var(--accent);
    font-weight: 400;
	font-size: 2.25rem;
	text-align: center;
}

p.meta {
    color: var(--sec-accent);
    margin-top: -1em;
	text-align: center;
}

blockquote {
  margin-top: 10px;
  margin-bottom: 10px;
  padding-left: 15px;
  border-left: 5px solid #ccc;
  color: #7e7e7e;
} 

nav {
    margin-bottom: 10px;
    margin-top: 10px;
}

table {
  margin-bottom: 1rem;
  width: 100%;
  border: 1px solid var(--fg-col);
  border-collapse: collapse;
}
td,
th {
  padding: .25rem .5rem;
  border: 1px solid var(--fg-col);
}
tbody tr:nth-child(odd) td,
tbody tr:nth-child(odd) th {
    background-color: #3b3f4f;
}

.container {
  max-width: 38rem;
  padding-left:  1rem;
  padding-right: 1rem;
  margin-left:  auto;
  margin-right: auto;
}

footer {
  bottom: 0px;
  text-align: center;
  font-size: 12px;
  padding-top: 20px;
}

.message {
  margin-bottom: 1rem;
  padding: 1rem;
  color: var(--sec-accent);
  border: solid var(--fg-col);
}

code {
  padding: .25em;
  font-size: 85%;
  color: var(--fg-col);
  background-color: #3b3f4f;
}

pre {
  display: block;
  margin-top: 0;
  margin-bottom: 1rem;
  padding: 1rem;
  border-radius: 5px;
  font-size: .8rem;
  line-height: 1.4;
  overflow-x: auto;
  background-color: #272727;
}
pre code {
  padding: 0;
  font-size: 100%;
  color: inherit;
  background-color: transparent;
}

@media only screen and (max-width: 600px) {
  html, body {
    font-size: 15px;
  }
  .container {
    padding-left: 0.0rem;
    padding-right: 0.0rem;
    max-width: 45rem;
  }
  blockquote {
  }
}

A  => template.html +68 -0
@@ 1,68 @@
<!DOCTYPE html>
<head>
	<meta charset="utf-8" />
	$for(author-meta)$
	<meta name="author" content="$author-meta$" />
	$endfor$
	$if(date-meta)$
	<meta name="dcterms.date" content="$date-meta$" />
	$endif$
	$if(keywords)$
	<meta name="keywords" content="$for(keywords)$$keywords$$sep$, $endfor$" />
	$endif$
	$if(description-meta)$
	<meta name="description" content="$description-meta$" />
	$endif$
	<title>$if(title-prefix)$$title-prefix$ – $endif$$pagetitle$</title>
	<style>
$styles.html()$
	</style>
	$for(css)$
	<link rel="stylesheet" href="$css$" />
	$endfor$
	$if(math)$
	$math$
	$endif$
	$for(header-includes)$
	$header-includes$
	$endfor$
</head>
<body>
	$for(include-before)$
	$include-before$
	$endfor$
	<div class="container">
		$if(title)$
		<h1 class="title">$title$</h1>
		$endif$
		$if(home)$
		<p class="meta">
		<a href="$home$">home</a>
		</p>
		$endif$
		$if(subtitle)$
		<p class="meta">$subtitle$</p>
		$endif$
		$if(author)$
		$for(author)$
		<p class="meta">$author$</p>
		$endfor$
		$endif$
		$if(date)$
		<p class="meta">Last edited: $date$</p>
		$endif$
		$if(toc)$
		<nav id="$idprefix$TOC" role="doc-toc">
			$if(toc-title)$
			<h2 id="$idprefix$toc-title">$toc-title$</h2>
			$endif$
			$table-of-contents$
		</nav>
		$endif$
		$body$
	</div>
	$for(include-after)$
	$include-after$
	$endfor$
</body>
</html>