~zenomat/tinywiki

bb7d8ea2741900033dc9d0655b8b1a6a36767119 — zeno 2 months ago c9f833a
Merge support for toc generation from rust branch

Toc support was accidentaly added in the rust branch, merged that over
3 files changed, 74 insertions(+), 59 deletions(-)

M README.md
M build.sh
M style.css
M README.md => README.md +6 -0
@@ 12,6 12,7 @@ Tinywiki is a simple bash script, which converts a folder into a static html wik

# Features
- File index insertion with [[index]]
- table of contents generation using frontmatter
- katex math (katex libs locally, so no external cdns)
- pandoc frontmatter
- subfolders


@@ 39,3 40,8 @@ cp style.css template.html $HOME/.local/share/tinywiki
- pass path of markdown folder to build.sh
- optionally pass basedir as second arg, if you want to deploy to a webserver
- open `<folder>/public_html/index.html`
- to generate a toc for a page, add
```yaml
toc: true
```
to the frontmatter

M build.sh => build.sh +6 -1
@@ 5,6 5,7 @@ function parse_yml()
	yml="$(awk 'f{ if (/---/){printf "%s", buf; f=0; buf=""} else buf = buf $0 ORS}; /---/{f=1}' "$1")"
	yml_data[0]="$(echo "$yml" | shyaml get-value title 2>/dev/null || echo "No title provided")"
	yml_data[1]="$(echo "$yml" | shyaml get-value desc 2>/dev/null || echo "No description provided")"
	yml_data[2]="$(echo "$yml" | shyaml get-value toc 2>/dev/null || echo "false")"
}

workdir="$(readlink -f "$1")"


@@ 71,7 72,11 @@ find . -name "*.md" ! -name "index-ins.md" | while read -r file; do
	done

	mkdir -p $outdir/$path
	pandoc -s --template="$outdir/assets/template.html" -V home="$path_to_root/index.html" --css=$path_to_root/assets/css/style.css --highlight-style breezedark -f markdown+hard_line_breaks --katex $outdir/tmp/"$name".md -o $outdir/$path/$name.html
	if [ "${yml_data[2]}" = "True" ]; then
		pandoc --toc -s --template="$outdir/assets/template.html" --variable home="$path_to_root/index.html" --css=$path_to_root/assets/css/style.css --highlight-style breezedark -f markdown+hard_line_breaks --katex $outdir/tmp/"$name".md -o $outdir/$path/$name.html
	else
		pandoc -s --template="$outdir/assets/template.html" --variable home="$path_to_root/index.html" --css=$path_to_root/assets/css/style.css --highlight-style breezedark -f markdown+hard_line_breaks --katex $outdir/tmp/"$name".md -o $outdir/$path/$name.html
	fi

	sed -i "s/https:\/\/cdn.jsdelivr.net\/npm\/katex@[0-9]*\.[0-9]*\.[0-9]*\/dist\/katex.min.css/$escaped_path_to_root\/assets\/css\/katex.min.css/g" "$outdir/$path/$name.html"
	sed -i "s/https:\/\/cdn.jsdelivr.net\/npm\/katex@[0-9]*\.[0-9]*\.[0-9]*\/dist\/katex.min.js/$escaped_path_to_root\/assets\/js\/katex.min.js/g" "$outdir/$path/$name.html"

M style.css => style.css +62 -58
@@ 3,32 3,30 @@
    --fg-col: #ffffff;
    --accent: #e93c58;
    --sec-accent: #9a9a9a;
	max-width: 42rem;
	max-width: 50rem;
	margin-left:  auto;
	margin-right: auto;
}

* {
  box-sizing: border-box;
	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;
	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;
	color: var(--accent);
	text-decoration: none;
}

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

h1, h2, h3, h4, h5, h6 {


@@ 68,50 66,56 @@ h6 {
}

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

hr {
    color: #ffffff;
	color: #ffffff;
}

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

p.meta {
    color: var(--sec-accent);
    margin-top: -1em;
	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;
} 
	margin-top: 10px;
	margin-bottom: 10px;
	padding-left: 15px;
	border-left: 5px solid #ccc;
	color: #7e7e7e;
}

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

nav#TOC {
	display: table;
	margin: 0 auto;
	text-align: left;
}

table {
  margin-bottom: 1rem;
  width: 100%;
  border: 1px solid var(--fg-col);
  border-collapse: collapse;
	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);
	padding: .25rem .5rem;
	border: 1px solid var(--fg-col);
}
tbody tr:nth-child(odd) td,
tbody tr:nth-child(odd) th {


@@ 119,42 123,42 @@ tbody tr:nth-child(odd) th {
}

footer {
  bottom: 0px;
  text-align: center;
  font-size: 12px;
  padding-top: 20px;
	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);
	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;
	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;
	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;
	padding: 0;
	font-size: 100%;
	color: inherit;
	background-color: transparent;
}

@media only screen and (max-width: 600px) {