чување 395b4360cf4efb591f4785b47220b7144dc8e993
родитељ b5e13d7941dbc8bb2b8e0a938166e002cd8cba3d
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Wed, 11 Nov 2020 21:20:55 +0100
Initial commit
Diffstat:
| A | .gitignore | | | 14 | ++++++++++++++ |
| A | Makefile | | | 40 | ++++++++++++++++++++++++++++++++++++++++ |
| A | README | | | 41 | +++++++++++++++++++++++++++++++++++++++++ |
| A | examples/index.slw | | | 10 | ++++++++++ |
| A | slweb | | | 188 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | slweb.1 | | | 125 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
измењених датотека: 6, додавања: 418(+), брисања: 0(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,14 @@
+*~
+*.bak
+*.orig
+*.rej
+*.o
+*.pdf
+*.ps
+*.swp
+nohup.out
+*.png
+*.gz
+
+examples/index.html
+
diff --git a/Makefile b/Makefile
@@ -0,0 +1,40 @@
+BINDIR=/usr/local/bin
+MANDIR=/usr/local/share/man/man1
+BROWSER=surf
+EXAMPLE_PAGES=$(addsuffix /index.slw,examples)
+EXAMPLE_PAGES_HTML=$(EXAMPLE_PAGES:.slw=.html)
+
+%.html: %.slw
+ ./slweb $^ > $@
+
+%.gz: %
+ gzip -kf $<
+
+%.ps: %.1
+ groff -mandoc -t -T ps $< > $@
+
+%.pdf: %.1
+ groff -mandoc -t -T pdf $< > $@
+
+all: examples doc
+
+examples: ${EXAMPLE_PAGES_HTML}
+
+view: examples
+ $(BROWSER) examples/index.html
+
+doc: slweb.pdf slweb.1.gz
+
+install: all
+ mkdir -p $(BINDIR) $(MANDIR)
+ cp slweb $(BINDIR)
+ cp slweb.1.gz $(MANDIR)
+
+uninstall:
+ rm $(BINDIR)/slweb $(MANDIR)/slweb.1.gz 2>/dev/null
+
+clean: slweb.1.gz slweb.pdf $(EXAMPLE_PAGES_HTML)
+ rm $^ 2>/dev/null
+
+.PHONY: examples view doc install uninstall clean
+
diff --git a/README b/README
@@ -0,0 +1,41 @@
+ slweb
+ =====
+
+Slweb is a static website generator which aims at being simplistic. It uses
+sed(1) to transform a custom Markdown-like syntax into HTML.
+
+
+ Install
+ -------
+
+$ git clone https://github.com/Strahinja/slweb.git
+$ cd slweb
+$ make && sudo make install
+
+
+ Examples
+ --------
+
+See the examples/ directory in this repository.
+
+
+ License
+ -------
+
+ slweb - Simple static website generator.
+ Copyright (C) 2020 Страхиња Радић
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+
diff --git a/examples/index.slw b/examples/index.slw
@@ -0,0 +1,10 @@
+site-name: Test website
+site-desc: My first website in slweb
+---
+
+{main}
+# Hello world
+
+This is an _example_ of a statically generated HTML.
+
+{/main}
diff --git a/slweb b/slweb
@@ -0,0 +1,188 @@
+#!/bin/sh
+
+BODY_ONLY=0
+CSSFILE=index.css
+INFILE=index.slw
+OUTFILE=index.html
+VERSION=v0.1-beta
+
+function throw()
+{
+ echo $1 1>&2
+ exit 1
+}
+
+function version()
+{
+ cat <<EOT
+Slweb $VERSION
+EOT
+ return 1
+}
+
+function usage()
+{
+ cat <<EOT
+usage: $(basename $0) [-b|--body-only] [-d <dir>|--basedir <dir>] [-h|--help] [-v|--version] <file>
+EOT
+ return 1
+}
+
+function begin_html()
+{
+cat <<EOT
+<!DOCTYPE html>
+<html lang="en">
+EOT
+}
+
+function end_html()
+{
+cat <<EOT
+</html>
+EOT
+}
+
+function begin_head()
+{
+cat <<EOT
+<head>
+EOT
+}
+
+function head()
+{
+cat <<EOT
+ <title>${VARS[site-name]}</title>
+ <meta charset="utf8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <meta name="generator" content="slweb" />
+EOT
+}
+
+function add_css()
+{
+ cat <<EOT
+ <link rel="stylesheet" href="$1" />
+EOT
+}
+
+function end_head()
+{
+cat <<EOT
+</head>
+EOT
+}
+
+function begin_body()
+{
+cat <<EOT
+<body>
+EOT
+}
+
+function body()
+{
+ BODY=$(echo "$1" | \
+ sed -e's/#### \([^\n]*\)$/<h4>\1<\/h4>/g' \
+ -e's/### \([^\n]*\)$/<h3>\1<\/h3>/g' \
+ -e's/## \([^\n]*\)$/<h2>\1<\/h2>/g' \
+ -e's/# \([^\n]*\)$/<h1>\1<\/h1>/g' \
+ -e 's/\*\*\([^*]\+\)\*\*/<strong>\1<\/strong>/g' \
+ -e 's/\*\([^*]\+\)\*/<em>\1<\/em>/g' \
+ -e 's/_\([^_]\+\)_/<em>\1<\/em>/g' \
+ -e 's/{\.\(.*\)}/<div class="\1">/' \
+ -e 's/{\/\.\(.*\)}/<\/div><!--\1-->/' \
+ -e 's/{#\(.*\)}/<div id="\1">/' \
+ -e 's/{\/#\(.*\)}/<\/div><!--\1-->/' \
+ -e "s/{made-by}/$MADEBY/g" \
+ -e 's/{\([a-z-]\+\)}/<\1>/g' \
+ -e 's/{\/\([a-z-]\+\)}/<\/\1>/g' \
+ -e "s/\\[\\([^]]\\+\\)\\](\\([^)]\\+\\))/<a href=\"$(realpath --relative-to=$BASEDIR $(dirname $INFILE) | sed -e's/\//\\\//g')\/\\2\">\\1<\\/a>/" | \
+ sed -e '1h;2,$H;$!d;g;s/\n\n\([^<{\n]\+\)/\n\n<p>\1/g' | \
+ sed -e '1h;2,$H;$!d;g;s/\([^>}\n]\)\n\n/\1<\/p>\n\n/g' | \
+ sed -e '1h;2,$H;$!d;g;s/\([^>}\n]\)$/\1<\/p>\n\n/g')
+
+ INCLUDE=$(echo "$BODY" | \
+ sed -e'/{include/s/.*{include \"\([.\/a-z ]\+\)\"}.*/\1/;t;d' | \
+ sed 1q)
+
+ while [ ! -z "$INCLUDE" ]; do
+ INCLUDE_BODY=$($0 -b -d $(dirname $INFILE) "$(dirname $INFILE)/$INCLUDE.slw")
+ BODY=$(echo "$BODY" | \
+ sed -e"s/{include \\\"$(echo $INCLUDE | sed -e's/\//\\\//g')\\\"}/$(echo $INCLUDE_BODY | sed -e's/\//\\\//g')/")
+ INCLUDE=$(echo "$BODY" | \
+ sed -e'/{include/s/.*{include \"\([.\/a-z ]\+\)\"}.*/\1/;t;d' | \
+ sed 1q)
+ done
+ echo "$BODY"
+}
+
+function end_body()
+{
+cat <<EOT
+</body>
+EOT
+}
+
+BASEDIR=.
+MADEBY=$(cat <<EOT | sed -e's/\//\\\//g' -e"s/\"/\\\\\"/g" | sed -z -e's/\n/\\n/g'
+<div id="made-by">
+Generated by <a href="https://github.com/Strahinja/slweb">slweb</a>
+© 2020 Strahinya Radich.
+</div><!--made-by-->
+EOT
+)
+
+while [ $# -gt 0 ]; do
+ case "$1" in
+ -v|--version) version; exit
+ ;;
+ -h|--help) usage; exit
+ ;;
+ -b|--body-only) BODY_ONLY=1
+ ;;
+ -d|--basedir) shift; BASEDIR=$1
+ ;;
+ *) INFILE=$1
+ ;;
+ esac
+ shift
+done
+
+[ -f $INFILE ] || throw "$INFILE not present"
+
+declare -A VARS
+VAR_KEYS=$(grep '\([a-z-]\+\): \(.*\)' $INFILE | \
+ sed -e's/\([a-z-]\+\): \(.*\)/\1/g')
+for key in $VAR_KEYS; do
+ VARS[$key]=$(grep "$key:" $INFILE | \
+ sed -e "s/$key: \(.*\)/\1/g")
+done
+
+#echo -n Generating ${VARS[site-name]}: ${VARS[site-desc]}...
+
+grep -- '---' $INFILE 2>&1 >/dev/null \
+ && DOC=$(sed '0,/---/d' $INFILE) \
+ || DOC=$(cat $INFILE)
+
+CSSHREF=$CSSFILE
+INDIR=$(dirname $INFILE 2>/dev/null)
+[ "$INDIR" != "." ] && CSSHREF=../$CSSFILE
+#echo CSSHREF=$CSSHREF >&2
+
+if [ $BODY_ONLY -eq 0 ]; then
+ begin_html
+ begin_head
+ head
+ [ -f $CSSFILE ] && add_css $CSSHREF
+ end_head
+ begin_body
+fi
+body "$DOC"
+if [ $BODY_ONLY -eq 0 ]; then
+ end_body
+ end_html
+fi
+
+#echo done.
diff --git a/slweb.1 b/slweb.1
@@ -0,0 +1,125 @@
+'\"
+.\" Manpage for slweb(1)
+.
+.mso an-ext.tmac
+.
+.TH SLWEB "1" "11 Nov 2020" "slweb v0.1-beta" "General Commands Manual"
+.SH NAME
+slweb \- Simple static website generator
+.
+.SH SYNOPSIS
+.SY slweb
+.RI [ options ]
+.RI [ filename ]
+.YS
+.
+.SH COPYRIGHT
+slweb Copyright \(co 2020 Strahinya Radich.
+.
+.SH DESCRIPTION
+.B Slweb
+is a static website generator which aims at being simplistic. It uses
+.BR sed (1)
+to transform a custom Markdown-like syntax into
+.SM HTML.
+.
+.SH OPTIONS
+.
+.TP
+.B \-b
+.TQ
+.B \-\-body\-only
+.br
+Only add the contents of the \fC<body>\fR tag, skipping \fC<html>\fR and
+\fC<head>\fR.
+.
+.TP
+.B \-d <\fIdirectory\fR>
+.TQ
+.B \-\-basedir <\fIdirectory\fR>
+.br
+Set the base directory as a reference point to normalize paths in local links
+(the argument to
+.B --relative-to
+option for the
+.BR realpath (1)
+command).
+.
+.TP
+.B \-h
+.TQ
+.B \-\-help
+.br
+Print this usage information screen.
+.
+.TP
+.B \-v
+.TQ
+.B \-\-version
+.br
+Print program version and exit.
+.
+.SH "SEE ALSO"
+.BR sed (1)
+.
+.SH EXAMPLES
+.
+.PP
+GIven the file \fCindex.slw\fR in the current directory:
+.EX
+.in +4
+.sp
+site-name: Test website
+site-desc: My first website in slweb
+---
+
+{main}
+# Hello world
+
+This is an _example_ of a statically generated HTML.
+
+{/main}
+.in -4
+.sp
+.EE
+after using the command:
+.EX
+.in +4
+.sp
+$ slweb index.slw > index.html
+.in -4
+.sp
+.EE
+file \fCindex.html\fR contains:
+.EX
+.in +4
+.sp
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>Test website</title>
+ <meta charset="utf8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <meta name="generator" content="slweb" />
+</head>
+<body>
+
+<main>
+<h1>Hello world</h1>
+
+<p>This is an <em>example</em> of a statically generated HTML.</p>
+
+</main>
+</body>
+</html>
+.in -4
+.sp
+.EE
+.
+.SH BUGS
+.
+.PP
+Bugs can be reported using the Github issue tracker at:
+.UR https://\:github.com/\:Strahinja/\:slweb/\:issues
+.UE
+