Objects - ReFreezed/LuaWebGen GitHub Wiki

Note: The documentation has moved to the LuaWebGen website. Information here may be out of date!

These are global objects.


site

These values can be configured in config.lua.

site.baseUrl

The base part of the website's URL, e.g. "http://www.example.com/".

site.defaultLayout

The default layout pages will use. The default value is "page" (which corresponds to the file layouts/page.html). Setting this to an empty string will make pages use no layout by default.

site.description

A description for the website.

site.languageCode

The code for the language of the website, e.g. "dk". (This doesn't do much yet, but will be used for i18n in the future.)

site.title

The title of the website.

page

Note that all fields become read-only after the page content has been generated (or after lock() has been called).

page.aliases

A list of URLs that point to previous locations of the page. This serves the same purpose as config.redirections. Example:

{{
-- Current file: a-better-omelet.md
page.title   = "Making a Better Omelet"
page.aliases = {"/how-to-make-omelet/", "/omelet-tutorial/"}
}}

page.content

[readonly] The HTML content of the page. Available in layouts (and later). Trying to access the content before it has finished generating or in an invalid situation will raise an error. Example:

<!-- layouts/page.html -->
<html>
	<head>
		<title>{{ page.title }}</title>
	</head>
	<body>
		{{ page.content }}
	</body>
</html>

page.date

What date the page was created. Even though the default value is the time the file was last modified (if that information is accessible by the program) it's still recommended that every page update this to an explicit value (otherwise the date may end up being 1970-01-01). See datetime for the date format. Also see page.publishDate and page.dateModified.

Note: Every page generated with generateFromTemplate() should update this value because there's no source file to grab the modified time from.

page.dateModified

[v1.3] What date the page was last modified. If this isn't set then the value of page.date is used. See datetime for the date format.

page.description

A description for the page.

page.isDraft

If the page is a draft. Drafts are excluded from the website build (unless the --drafts option is used).

page.isHome

[readonly] If the page is the root index page, aka the homepage.

page.isIndex

[readonly] If the page is an index page.

page.isPage

[readonly] If the page is in fact a page. This value is true for HTML/Markdown files, and false for CSS files for example.

page.isSpecial

If the page is some kind of special page. Special pages are ignored by subpages(). Set this to true for e.g. 404 error pages.

page.layout

What layout the page should use. The default is the value of site.defaultLayout. Setting this to an empty string will make the page not use any layout.

page.params

[readonly] Table for storing any custom data you want. Also see the params/P aliases. Note that while the table itself cannot be swapped out, fields of the table can be updated freely.

page.permalink

[readonly] The permanent URL for the page. This URL is absolute.

page.publishDate

What date the page was, or is going to be, published. If the date is in the future (or past the date specified by the --date option) then the page is excluded from the website build. If this isn't set then the value of page.date is used. See datetime for the date format.

page.redirectionTarget

[readonly] On redirection pages, this value is set to the redirection target URL. Otherwise, it's empty.

page.title

The title of the page. Every page should update this value.

page.url

[readonly] The relative URL to the page on the site.

Note: If site.baseUrl has a path containing a subdirectory then this URL is relative to that directory and not to the host name. For example, if site.baseUrl is "http://example.com/abc/" then page.url for the file content/foo.md will be "/foo/" and page.permalink will be "http://example.com/abc/foo/". Or, in other words, page.url for a file will always be the same no matter what site.baseUrl is. Use url() to safely link to a page using page.url.

Other Objects

data

Access data from the data folder. Type e.g. data.cats to retrieve the contents of data/cats.lua or data/cats.toml. Files can be in subfolders (e.g. type data.foo.bar to access data/foo/bar.toml). See DATA_FILE_EXTENSIONS for supported data formats.

params

params or P

Table for storing any custom data you want. Aliases for page.params.

scripts

[v1.3] Access scripts from the scripts folder. Type e.g. scripts.foo() to call the function returned by of scripts/foo.lua. Files can be in subfolders (e.g. type scripts.abc.xyz to access scripts/abc/xyz.lua).

Note that scripts can be accessed with or without the prefix scripts. - this object mostly exists in case there's a name conflict between a script and one of LuaWebGen's existing globals.

⚠️ **GitHub.com Fallback** ⚠️