Then there is the low tech approach which I used for my not-so-state-of-the-art website, i.e. design a basic template page and for each new page (e.g. this blog post), duplicate the HTML file adding content. This cheap and cheerful approach will hit into problems if I ever want to change the looks of the website though.
If you are a C/C++ programmer you will be familiar with header files that are #included in source code files with common code blocks and #defined preprocessor variables. With a few changes in the header file you can modify all the source code that includes it. So here's a crazy idea: is it possible to use visual studio's preprocessor as a substitute for Hugo, Jekyll and all the rest of it? As it turns out you can, but only hard core programmers need apply :)
Visual studio's compiler has the /EP switch that just runs the preprocessor without compiling any code. It just inserts all the included files and the defined variables and emits the resulting text. Hence it can be used to automatically generate HTML pages using #include and #define directives! Here is an example:
|common header||intermediate html||final page|
// header.h (shared html) // variable date #define COPYRIGHT (c) 2017 zabkat // heading shared in many html files <h1>Wonderful website heading</h1> // ... other shared stuff
// test.c (html page to be) <html><body> // variable definitions here #include "header.h" <p>this is a website compiled in C! // copyright date from header <p>COPYRIGHT </body></html>
The first file HEADER.H has all the common html (or rather a HTML block) and variables like COPYRIGHT all expressed in C preprocessor compatible format. This header is then included in the actual html page and we let the C compiler generate the output .HTM file as such:
%MSVCDIR%\bin\cl.exe /EP /nologo test.c > out.htm
Here are the party tricks we've used:
(we could have combined /EP /P to generate a file but that would have .I extension and we'd need to rename it)
With this simple system we can have any number of shared html blocks and include them in various pages. Whenever we need to change the format, or to change a variable (e.g. the copyright date changing chore that spoils every webmaster's new year day), we only need to change 2-3 header files and the website will be automatically updated after this primitive compilation.
Managing a whole website with visual studio
A large website will be made of 2-3 common header files and a number of .C (pre-html) files with the actual pages. Each page will need to be compiled to generate the final static website. Quite possibly you can create a visual studio project or a makefile for this precompilation task. But using xplorer² you can simply use a command script <Ctrl+B> to operate on all the selected .C files in one go:
So there you have it, visual studio based wordpress killer for the fastest most responsive websites <g>
Post a comment on this topic »