static html builder
This commit is contained in:
@@ -34,3 +34,12 @@ Only 1st level heads and links are parsed. The rest are printed as is:
|
||||
[link name](link url)
|
||||
|
||||
```
|
||||
|
||||
## Static HTML builder
|
||||
|
||||
Sometimes the reloading of styles and links is hard due to caching.
|
||||
You can create a fully static single HTML page with:
|
||||
|
||||
```
|
||||
bash build_static.sh -l example_links.txt -c config.js -s style.css > templated.html
|
||||
```
|
||||
|
||||
95
build_static.sh
Normal file
95
build_static.sh
Normal file
@@ -0,0 +1,95 @@
|
||||
#!/bin/bash
|
||||
|
||||
_help() {
|
||||
echo "Pass arguments to create a static version of the index, printed on stdout
|
||||
Templating will replace config values config.style and config.source to null
|
||||
|
||||
-l [links.txt] Path to links.txt. must be passed
|
||||
-c [config.js] *Path to configuration js replacing config values
|
||||
-s [styles.css] *Path to extra styles
|
||||
|
||||
* can be left out
|
||||
"
|
||||
exit
|
||||
}
|
||||
|
||||
_checkenv() {
|
||||
if [[ ! -e "$LINKS" ]]; then
|
||||
echo "Links file '$LINKS' not found."
|
||||
_help
|
||||
exit 1
|
||||
fi
|
||||
if [[ -n "$CONFIG" ]]; then
|
||||
if [[ ! -e "$CONFIG" ]]; then
|
||||
echo "Config file '$CONFIG' not found."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
if [[ -n "$STYLE" ]]; then
|
||||
if [[ ! -e "$STYLE" ]]; then
|
||||
echo "Styles file '$STYLE' not found."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "
|
||||
Links file: $LINKS
|
||||
Config file: $CONFIG
|
||||
Style file: $STYLE
|
||||
" >&2
|
||||
|
||||
}
|
||||
_replace_links() {
|
||||
if [[ -e "$LINKS" ]]; then
|
||||
sed \
|
||||
-e '/TEMPLATED:LINKS/a config.source=null;' \
|
||||
-e '/TEMPLATED:LINKS/a config.links=`' \
|
||||
-e "/TEMPLATED:LINKS/r $LINKS" \
|
||||
-e '/TEMPLATED:LINKS/a `;'
|
||||
#-e "/TEMPLATED:LINKS/d"
|
||||
else
|
||||
cat -
|
||||
fi
|
||||
}
|
||||
_replace_config() {
|
||||
if [[ -e "$CONFIG" ]]; then
|
||||
sed \
|
||||
-e "/TEMPLATED:CONFIG/r $CONFIG" \
|
||||
-e "/^.script language.*config.js.*script.*/d"
|
||||
#-e "/TEMPLATED:CONFIG/d"
|
||||
else
|
||||
cat -
|
||||
fi
|
||||
}
|
||||
_replace_style() {
|
||||
if [[ -e "$STYLE" ]]; then
|
||||
sed \
|
||||
-e "/TEMPLATED:STYLE/r $STYLE" \
|
||||
-e '/TEMPLATED:CONFIG/a config.style=null;' \
|
||||
#-e "/TEMPLATED:STYLE/d"
|
||||
else
|
||||
cat -
|
||||
fi
|
||||
}
|
||||
|
||||
_replace() {
|
||||
|
||||
cat index.html | _replace_links | _replace_config | _replace_style
|
||||
|
||||
}
|
||||
|
||||
CONFIG=
|
||||
STYLE=
|
||||
LINKS=
|
||||
|
||||
for (( i=1; i<=$#; i++ )); do
|
||||
j=$(( i + 1 ))
|
||||
[[ "${!i}" = "-h" ]] && _help
|
||||
[[ "${!i}" = "--help" ]] && _help
|
||||
[[ "${!i}" = "-l" ]] && { LINKS="${!j}"; shift 1; continue; }
|
||||
[[ "${!i}" = "-c" ]] && { CONFIG="${!j}"; shift 1; continue; }
|
||||
[[ "${!i}" = "-s" ]] && { STYLE="${!j}"; shift 1; continue; }
|
||||
done
|
||||
|
||||
_checkenv
|
||||
_replace
|
||||
23
index.html
23
index.html
@@ -48,13 +48,14 @@
|
||||
}
|
||||
.blink {
|
||||
-webkit-animation: blinker 0.5s infinite;
|
||||
-moz-animation: blinker 0.5s infinite;
|
||||
animation: blinker 0.5s infinite;
|
||||
-moz-animation: blinker 0.5s infinite;
|
||||
animation: blinker 0.5s infinite;
|
||||
}
|
||||
@keyframes blinker {
|
||||
0% { opacity: 0.00; }
|
||||
100% { opacity: 1.00; }
|
||||
}
|
||||
/* TEMPLATED:STYLE */
|
||||
</STYLE>
|
||||
<script language="javascript">
|
||||
function init() {
|
||||
@@ -269,16 +270,21 @@ function reload_source() {
|
||||
function get_URL(s) {
|
||||
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
|
||||
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
|
||||
xmlhttp.onreadystatechange=function()
|
||||
{ if (xmlhttp.readyState==4 && xmlhttp.status==200)
|
||||
{ parse_links(xmlhttp.responseText);
|
||||
}}
|
||||
xmlhttp.onreadystatechange=function() {
|
||||
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
|
||||
parse_links(xmlhttp.responseText);
|
||||
}
|
||||
}
|
||||
xmlhttp.open("GET", s, true);
|
||||
xmlhttp.send();
|
||||
}
|
||||
|
||||
function read_links() {
|
||||
get_URL(config.source);
|
||||
if (config.source === null && config.links) {
|
||||
parse_links(config.links);
|
||||
} else {
|
||||
get_URL(config.source);
|
||||
}
|
||||
}
|
||||
|
||||
function parse_links(s) {
|
||||
@@ -498,7 +504,8 @@ var config = {
|
||||
arrows:['📙','📚'], // Arrow characters for in/out tab icon
|
||||
foldCategories:true // fold categories in single column mode
|
||||
};
|
||||
|
||||
// TEMPLATED:CONFIG
|
||||
// TEMPLATED:LINKS
|
||||
</script>
|
||||
<script language="javascript" src="config.js"></script>
|
||||
</head>
|
||||
|
||||
Reference in New Issue
Block a user