Thuban : swx - static site generator
vendredi 25 mai 2018 à 19:23swx - static site generator
swx is now here : swx.
swx is a tool to generate a static website from a file tree written in [markdown http://daringfireball.net/projects/markdown/syntax], [txt2tags http://txt2tags.org/] or any other markup language.
It does'nt require any other tool except usal commands (cp, sed…) and the markup parser.
Inspired by sw, swx will generate you html pages, create links between them in a menu. You cas use simple css and templates that will be included in your pages.
Features
- Convert markdown to html
- Add menu between pages
- Ignore some files in a blacklist
- Generate a rss feed : see swx_rss
- Generate a blog page. For comments, use [Hashover http://tildehash.com/?page=hashover] or Disqus.
- Generate a site map see swx_plan
- Generate a sitemap for web indexers see swx_sitemap
- Use a Makefile to simplify the site generation see Makefile
Example : source tree
/home/user/site/
|style.css
|--------------directory/
|-----------------------index.md
|-----------------------file1.md
|-----------------------image.jpg
|--------------directory2/
|-----------------------index.t2t
|-----------------------article.md
will become in output
/home/user/site.static/
|style.css
|--------------directory/
|-----------------------index.html
|-----------------------file1.html
|-----------------------image.jpg
|--------------directory2/
|-----------------------index.html
|-----------------------article.html
Install
Download files here here
Using
Simple run :
./swx directory_containing_website
then, push you site the way you prefer with mercurial, git, rsync or even ftp
Configuration
To configure, edit swx.conf
You can change uppercase variables to fit your needs
BL
: blacklist, the files that won’t be in the menuCONVERTER
: tool to convert sources . Pour txt2tags :CONVERTER='txt2tags -t html -o- --no-headers'
.EXT=".md"
: extension of files to convertFOOTER
: what you want in footerHEADER
: what you want in headerTOPTEMPLATE
: this will be included before the text of your pages Note that the default config file allows you to have a link to the to of the page.BOTTOMTEMPLATE
: text included between your text and footer.
Modyfy how your site looks with style.css
Example
mkdir dossier
cd dossier
wget http://dev.yeuxdelibad.net/swx.tgz
tar xvzf swx.tgz
mkdir monsite
vim monsite/index.md
vim monsite/page1.md
mkdir monsite/dossier1
vim monsite/dossier1/index.md
./swx/swx monsite
Appears monsite.static
containing every pages converted to html and a new
file swx.log
containing the list of news pages (used later)
RSS feed
Use swx_rss
to generate feed.xml
./swx_rss > DESTDIR/feed.xml
Replace DESTDIR
the path to the output directory
Site map
Generate a list of pages in your site with
./swx_plan DESTDIR > DESTDIR/Divers/map.html
And replace of course : DESTDIR
Sitemap generator
./swx_sitemap DESTDIR > DESTDIR/sitemap.xml
Then, you can compress it :
gzip --best -c DESTDIR/sitemap.xml > DESTDIR/sitemap.gz
Don’t forget to edit robots.txt
User-agent: *
Disallow:
Sitemap: http://votredomaine.net/sitemap.gz
Makefile
Example Makefile to edit to fit your needs:
SOURCEDIR=$(CURDIR)/example
DESTDIR=$(CURDIR)/example.static
all:
./swx $(SOURCEDIR)
./swx_gopher $(SOURCEDIR)
./swx_sitemap $(DESTDIR) > $(DESTDIR)/sitemap.xml
gzip --best -c $(DESTDIR)/sitemap.xml > $(DESTDIR)/sitemap.gz
./swx_plan $(DESTDIR) > $(DESTDIR)/siteplan.html
./swx_rss > $(DESTDIR)/feed.xml
./swx_blog $(DESTDIR)/index.html
clean:
rm -rf *.static
rm swx.log
force:
find Rendez-vous_sur_Arrakis -exec touch {} \\;
make all
serve:
cd $(DESTDIR) && python3 -m http.server && x-www-browser http://localhost:8000
Then, just run :
make
: build/update your sitemake clean
: Delete the sitemake force
: Force rebuild, event non-recent filesmake serve
: test site (python required) at http://localhost:8000
The end
Most of script can be improved, and simplified.
Avoid weird file names (use detox
!)
Do not hesitate to contact me for any suggestion here
Original post of Thuban.Votez pour ce billet sur Planet Libre.