Skip to content

Instantly share code, notes, and snippets.

@flaki
Created June 8, 2020 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flaki/6b66132c3ae4edb7eb3eed5c03b840f5 to your computer and use it in GitHub Desktop.
Save flaki/6b66132c3ae4edb7eb3eed5c03b840f5 to your computer and use it in GitHub Desktop.
Host the docs of better-sqlite3 (npm) on a local nginx server for offline access
# ...
127.0.0.1 better-sqlite3.docs.local
server {
listen 80;
# Address
server_name better-sqlite3.docs.local;
# looks like for autoindex to work root needs to be outside of the location
# https://forum.nginx.org/read.php?11,3810,83721#msg-83721
root /usr/share/nginx/better-sqlite3-docs;
location / {
index index.html;
# enable directory indexes
# http://nginx.org/en/docs/http/ngx_http_autoindex_module.html
autoindex on;
# adds extensions for nice urls & directory indexes
# http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files
# need $uri/ for autoindexing
# https://serverfault.com/questions/491671/using-nginx-try-files-and-autoindex-together
try_files $uri $uri.html $uri/ =404;
}
}
#!/bin/sh
# This is a sparse checkout (http://scriptedonachip.com/git-sparse-checkout)
# of just the docs/ folder of https://github.com/JoshuaWise/better-sqlite3
# get latest version of the docs
git pull --depth 2 origin master
# generate markdown
for file in ./docs/*.md; do
# https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion
outfile=${file/.md/.html}
outfile=${outfile/docs\//}
echo "Compiling $file -> $outfile..."
# create the html file from the markdown applying a specific stylesheet to all docs
npx -q --package markdown-to-html github-markdown --stylesheet "./.assets/stylesheet.css" "$file" > "$outfile"
# fix anchors
sed -i "s/<a id=\"user-content-/<a id=\"/g" "$outfile"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment