Skip to content

Instantly share code, notes, and snippets.

@katt64
Last active December 7, 2017 21:06
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 katt64/0057e56b2fee4b93612e33b4aa66477a to your computer and use it in GitHub Desktop.
Save katt64/0057e56b2fee4b93612e33b4aa66477a to your computer and use it in GitHub Desktop.
This facillitates includes in HTML files. Read http://docdro.id/5TojoNS
#!/bin/sh
# publish.sh Publishes HTML documents by processing inclusion lines.
#
# Stephanie B.
SOELIMDIR=pub/.soelim.$$
[ -d pub ] && rm -rf pub
mkdir -p $SOELIMDIR
for f in `find -regex ".+\.s?html?"`
do
[ ! -d "$SOELIMDIR/`dirname "$f"`" ] && mkdir -p "$SOELIMDIR/`dirname "$f"`"
sed -r "s@^<include (.+\.s?html?) />@.so $SOELIMDIR/`dirname "$f"`/\1@" \
"$f" > "$SOELIMDIR/$f"
done
for f in `find $SOELIMDIR -exec grep -qE "^\.so" "{}" \; -regex ".+\.s?html?" \
-print 2> /dev/null | sed -r "s_$SOELIMDIR/(.+)_\1_"`
do
[ ! -d "pub/`dirname "$f"`" ] && mkdir -p "pub/`dirname $f`"
soelim -r "$SOELIMDIR/$f" > "pub/$f"
done
rm -rf $SOELIMDIR
.de CBEGIN
.(l
.fam C
..
.de CEND
.)l
.fam T
..
.+c
.sp |0.5i
.ad c
.ps 20
publish.sh
.sp
.ps 14
.q Includes
for
.sm HTML
via Shell Script.
.sp
Stephanie B.
.ad l
.sz 10
.uh "Introduction"
.pp
.bi publish.sh
is a shell script that facillitates the inclusion of other
.sm HTML
documents at the behest of some instructions within some HTML documents.
To clarify, this shell script makes it possible for you to fragment your large
HTML document into smaller pieces and connect them into one main
.sm HTML
file by interspersing a request to include those smaller files in the main file.
.uh "Example"
.pp
For a web project, you may have many user-visible pages, like \fIindex.html\fP,
\fIabout.html\fP, \fIcontact.html\fP, &c.
You may also have the same headers, navigation features, footers, and other
features that are identical among those pages.
Classical
.sm HTML
does not allow you to feasibly outsource headers, footers, and the likes to
other smaller
.sm HTML
files.
This means that if you must correct/update something in the headers/footers,
you might as well just fucking kill yourself, okay?
.pp
Assuming that you have outsourced your title and navigations to a
\fIheader.html\fP and copyright notices to a \fIfooter.html\fP, that you have
outsourced one of the sections to \fIsections/stuff.html\fP, and that you have
downloaded this script, your \fIindex.html\fP could look something like this:
.CBEGIN
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My website :: Home page</title>
</head>
<body>
<header>
<include header.html />
</header>
<section class="stuff">
<include sections/stuff.html />
</section>
<footer>
<include footer.html />
</footer>
</body>
</html>
.CEND
.pp
You can use these include tags within other files to be included as well,
esentially nesting the includes: an include within \fIheader.html\fP, for
example.
.bi Note
that all include lines must not be indented or else it will not work!
.pp
As can be expected, the lines with \fC<include\fP will get replaced by the
contents of the file to which they refer.
If there are nested inclusions, the includes within the inclusions within ...
will get replaced as well!
.pp
Of course, you need to run the shell script to really get the includes to
function.
Place the shell script in the same directory as your other
.sm HTML
files (\fIindex.html\fP, &c.)
Once run, your published, fully-resolved version of your website will end up in
\fCpub/\fP, from which you can navigate and view on a browser.
Do take note that the indentations of the resolved version will suck a bit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment