Content Files

Guide to writing content files

Nift bunny mascot

Escaping characters

Nift will escape the following characters: ˜, !, @, #, %, ^, *, ?, <, >. Just put \character-to-escape, for example to escape tilde use .

Note: Nift does not, and will not, escape \$. This is because it conflicts with MathJax escaping \$. If you do not want to use MathJax on your site and want \$ escaped then manually uncomment the relevant code in PageBuilder.cpp before compiling and installing Nift.

Nift does not escape & as it causes problems with some valid javascript code for example (not an issue with .js files, but is an issue for javascript code inside content/template files). You can program your own syntax for escaping & in to Nift if needed. Similarly if javascript code or otherwise is not working, one thing to try is searching for \ in all the content/template files and seeing if something is being escaped inside code, if it is comment the relevant escape code from PageBuilder.cpp then compile and install Nift again.

Inputting pagetitle information

The title of a page may be inputted using @pagetitle. For example in the file template/head.content you may want something along the lines of sitename - @pagetitle.

Inputting OS information

You can use @buildOS to add whether a page was built using Nift on Linux, Macintosh or Windows (@currentOS will continue to do the same for backwards compatibility purposes).

Inputting date, time and timezone information

The date and time that a page was built may be inputted using @builddate and @buildtime (@currentdate and @currenttime will continue to do the same for backwards compatibility purposes). The timezone this date and time information is associated with may also be inputted using @buildtimezone (@timezone will continue to do the same for backwards compatibility purposes).

The date and time that a page was loaded may be inputted using @loaddate and @loadtime. The timezone this date and time information is associated with (ie. where the user is browsing the internet from) may also be inputted using @loadtimezone.

Also available are @buildUTCtime, @buildUTCdate, @buildYY and @buildYYYY (with @currentUTCtime, @currentUTCdate, @currentYY and @currentYYYY doing the same for backwards compatibility purposes), along with @loadUTCtime, @loadUTCdate, @loadYY and @loadYYYY.

String variables

You can define string variables using @stringdef(varName = varValue), where varName is the variable name and varValue is the variable value. For example you might have:

@stringdef(str = "hello, world!")

Note: variable names cannot contain the characters '=', ')' or ' '.

Note: you can use \' for ' and \" for " in variable values.

You can reference string variables using @string(varName), where varName is the variable name. For example to reference the string defined above use:

@string(str)

Inputting text from other files

Text may be inputted from another file using @input(path-to-file), where path-to-file is the path from the main site directory to the input file.

For example suppose inside your website directory you have template/footer.content:

Page was last built on @currentdate.

To input template/footer.content into another file write:

@input("template/footer.content")

Note: Nift will not let you create an input loop, for example you cannot have @input(page.template) inside page.template, or any of the files that page.template inputs, or any of the files that they input, and so on.

Path from pages to other pages/files

It is possible for pages $A$ and $B$ to be located in distinct directories yet input text from the same content file $X$. Consequently if content file $X$ contains a path to another page $Y$, you have the problem that the path from $A$ to $Y$ is not the same as the path from $B$ to $Y$. You can solve this non-constant path problem by using @pathto(page-name) or @pathtopage(page-name) where page-name is the page name for $Y$. When building a page, Nift will replace @pathto(page-name) with the path from the page being built to page $Y$.

An example of when users may find this useful is when writing menus for page templates, or adding local links for any template files. An example of a smaller version of the menu for this site using @pathto(page-name) is below:

<nav>
	<ul class="drop_menu">
		<li></li>
		<li class="dm_li">
			<a href="@pathto(index)">Home</a>
		</li>

		<li class ="dm_li">
			<div class="dm_text">Documentation</div>
			<ul class ="drop_submenu">
				<li class="dsm_li"><a href="@pathto(documentation/installing_nift)">Installing Nift</a></li>
				<li class="dsm_li"><a href="@pathto(documentation/nift_tutorial)">Nift tutorial</a></li>
				<li class="dsm_li"><a href="@pathto(documentation/nift_commands)">Nift commands</a></li>
			</ul>
		</li>

		<li class ="dm_li">
			<a href="@pathto(support)">Support</a>
		</li>
		<li></li>
	</ul>
</nav>

When using @pathto(page-name) or @pathtopage(page-name), Nift will throw an error if the page is not being tracked by Nift. You can solve the non-constant path problem for arbitrary files by using @pathtofile(path-to-file) where path-to-file is the path from the main site directory to file $Y$ (where page $Y$ above has been replaced with file $Y$). When building a page, Nift will throw an error if the file does not exist.

The footer content file for this site (inputted in the template/page.template file) is given below as an example using @pathtofile(path-to-file):

<footer>
	<hr>
	<center><img src="@pathtofile(site/files/nsm.png)" width="120"></center>

	<p>
		<b>Mirrors:</b> [<a href="https://nift.cc/">Official</a>] [<a href="https://nifty-site-manager.bitbucket.io/">BitBucket</a>] [<a href="https://nifty-site-manager.github.io/">GitHub</a>] [<a href="https://nifty-site-manager.gitlab.io/">GitLab</a>]
	</p>

	<p>
		<b>Repos:</b> [<a href="https://bitbucket.org/nifty-site-manager/nsm/src/master/">BitBucket</a>] [<a href="https://github.com/nifty-site-manager/nsm">GitHub</a>] [<a href="https://gitlab.com/nifty-site-manager/nsm">GitLab</a>]
	</p>

	Page was last built on @currentdate at @currenttime (@timezone) using @currentOS. <br>

	<noselect><small>© 2015-@loadYY <a href="https://n-ham.com/">Nicholas Ham</a></small></noselect>
</footer>

Adding page dependencies

Page dependencies may be added using @dep(dep-path), where dep-path is the path from the project root directory to the dependency file.

You can also add page dependencies manually by adding a .deps file residing in the same directory as the content file for the page. For example if you have index.content as the page content file add an index.deps file containing the extra dependencies you want to track.

Running scripts

Scripts may be run using @script(script-path), where script-path is the path from the project root directory to the script, which is basically the same as the system call for the script.

For example if you want to run a scripts 'script.py', you can do so with:

@script('./script.py')
Note: You should use single outer quotes and double inner quotes if running a program or script with spaces in the name.

Note: You should prepend ./ before scripts and programs so that your websites will build cross-platform (provided you use cross-platform scripting/programming languages, tools etc.).

Inputting script output

Output from scripts may be inputted at any point when building webpages using @scriptoutput(script-path), where where script-path is the path from the project root directory to the script, which is basically the same as the system call for the script. This can be incredibly useful for things like conditional statements/loops, or integrating with databases, GraphQL and scripting languages etc., which is just the tip of the ice berg!

For example suppose you want to input the output from running a script "linux script.py", you can do so with:

@scriptoutput('./"linux script.py"')
Note: You should use single outer quotes and double inner quotes if running a program or script with spaces in the name.

Note: You should prepend ./ before scripts and programs so that your websites will build cross-platform (provided you use cross-platform scripting/programming languages, tools etc.).

Running system calls

System calls may be run using @system(system-call), where system-call is the system call or you want to run.

For example suppose you want to run "test prog.exe", you can do so with:

@system('./"test prog.exe"')
Note: You should prepend ./ before scripts and programs so that your websites will build cross-platform (provided you use cross-platform scripting/programming languages, tools etc.).

Note: You should use single outer quotes and double inner quotes if running a program or script with spaces in the name.

Note: you can use \' for ' and \" for " in system-calls.

Inputting system call output

Output from system calls may be inputted at any point when building webpages using @systemoutput(system-call), where system-call is the system call or script you want to run. This can be incredibly useful for things like conditional statements/loops, inputting text from a url using cURL, or integrating with databases, GraphQL and scripting languages etc., which is just the tip of the ice berg!

Note: You should use single outer quotes and double inner quotes if running a program or script with spaces in the name.

Note: You should prepend ./ before scripts and programs so that your websites will build cross-platform (provided you use cross-platform scripting/programming languages, tools etc.).

Note: you can use \' for ' and \" for " in system-calls.

For example suppose you want to input the text from this paste on Paste Bin, you can do so with:

@systemoutput("curl -sS https://pastebin.com/raw/atjKuxY6")

Including css files

You can include a css file using @cssinclude(path-to-css-file), where path-to-css-file is the path from the main site directory to the css file (not the path from the page to the css file). When building a page, Nift will replace @cssinclude(path-to-css-file) with:

<link rel='stylesheet' type='text/css' href='path-from-page-to-css-file'>

Alternatively you can use:

<link rel='stylesheet' type='text/css' href='@pathtofile(path-to-css-file)'>

Including img files

You can include am image file using @imginclude(path-to-img-file), where path-to-img-file is the path from the main site directory to the img file (not the path from the page to the img file). When building a page, Nift will replace @imginclude(path-to-img-file) with the following:

<img src="path-from-page-to-img-file">

If you would like to set the width of an image, use something like the following in your source code:

<img src="@pathtofile(path-to-img-file)" width="120">

Including js files

You can include a js file using @jsinclude(path-to-js-file), where path-to-js-file is the path from the main site directory to the js file (not the path from the page to the js file). When building a page, Nift will replace @jsinclude(path-to-js-file) with:

<script src="path-from-page-to-js-file"></script>

Alternatively you can use:

<script src="@pathtofile(path-to-js-file)"></script>

Including a favicon file

You can include a favicon file using @faviconinclude(path-to-favicon-file), where path-to-favicon-file is the path from the main site directory to the favicon file (not the path from the page to the favicon file). When building a page, Nift will replace @faviconinclude(path-to-favicon-file) with:

<link rel='icon' type='image/png' href='path-from-page-to-favicon-file'>

Alternatively you can use:

<link rel='icon' type='image/png' href='@pathtofile(path-to-favicon-file)'>

An example of using @cssinclude(path-to-css-file), @jsinclude(path-to-js-file) and @faviconinclude(path-to-favicon-file) is given below (I typically put these in a head.content file located in the template directory and included in the template/page.template file in between the <head></head> tags):

@cssinclude("site/css/pagestyle.css")
@jsinclude("site/js/motion.css")
@faviconinclude("site/files/favicon.ico")