liara package#

liara.actions module#

class liara.actions.LinkType(value)#

Bases: enum.Enum

An enumeration.

External = 2#
Internal = 1#

Gather links across documents.

Returns

A dictionary containing a link, and the list of document paths in which this link was found.

Validate external links.

This issues a request for each link, and checks if it connects correctly. If not, an error is printed indicating the link and the documents referencing it.

Validate internal links.

For each link, check if it exists inside the provided site. If not, an error is printed indicating the link and the documents referencing it.

liara.cache module#

class liara.cache.Cache#

Bases: abc.ABC

Interface for key-value caches.

abstract get(key: bytes) Optional[object]#

Get a stored object.

Parameters

key – The object key.

Returns

An object if one exists. Otherwise, return None.

persist() None#

Persists this cache to disk/persistent storage.

This function should be called after the cache has been populated. On the next run, the constructor will then pick up the index and return cached data.

abstract put(key: bytes, value: object) bool#

Put a value into the cache using the provided key.

Parameters
  • key – The key under which value will be stored.

  • value – A pickable Python object to be stored.

Returns

True if the value was added to the cache, False if it was already cached.

class liara.cache.FilesystemCache(path: pathlib.Path)#

Bases: liara.cache.Cache

A Cache implementation which uses the filesystem to cache data.

This cache tries to load a previously generated index. Use persist() to write the cache index to disk.

get(key: bytes) Optional[object]#

Get a stored object.

Parameters

key – The object key.

Returns

An object if one exists. Otherwise, return None.

persist()#

Persists this cache to disk/persistent storage.

This function should be called after the cache has been populated. On the next run, the constructor will then pick up the index and return cached data.

put(key: bytes, value: object) bool#

Put a value into the cache using the provided key.

Parameters
  • key – The key under which value will be stored.

  • value – A pickable Python object to be stored.

Returns

True if the value was added to the cache, False if it was already cached.

class liara.cache.MemoryCache#

Bases: liara.cache.Cache

An in-memory Cache implementation.

This cache stores all objects in-memory.

get(key: bytes) Optional[object]#

Get a stored object.

Parameters

key – The object key.

Returns

An object if one exists. Otherwise, return None.

put(key: bytes, value: object) bool#

Put a value into the cache using the provided key.

Parameters
  • key – The key under which value will be stored.

  • value – A pickable Python object to be stored.

Returns

True if the value was added to the cache, False if it was already cached.

class liara.cache.NullCache#

Bases: liara.cache.Cache

The null cache drops all requests and does not cache any data.

This is mostly useful to disable caching in APIs which require a cache instance.

get(key: bytes) Optional[object]#

Get a stored object.

Parameters

key – The object key.

Returns

An object if one exists. Otherwise, return None.

put(key: bytes, value: object) bool#

Put a value into the cache using the provided key.

Parameters
  • key – The key under which value will be stored.

  • value – A pickable Python object to be stored.

Returns

True if the value was added to the cache, False if it was already cached.

class liara.cache.RedisCache(host: str, port: int, db: int, expiration_time=datetime.timedelta(seconds=3600))#

Bases: liara.cache.Cache

A cache using Redis as the storage backend.

get(key) Optional[object]#

Get a stored object.

Parameters

key – The object key.

Returns

An object if one exists. Otherwise, return None.

put(key: bytes, value: object) bool#

Put a value into the cache using the provided key.

Parameters
  • key – The key under which value will be stored.

  • value – A pickable Python object to be stored.

Returns

True if the value was added to the cache, False if it was already cached.

class liara.cache.Sqlite3Cache(path: pathlib.Path)#

Bases: liara.cache.Cache

A Cache implementation which uses SQLite to store the data. This is mostly useful if creating many files is slow, for instance due to anti-virus software.

This cache tries to load a previously generated index. Use persist() to write the cache index to disk.

get(key: bytes) Optional[object]#

Get a stored object.

Parameters

key – The object key.

Returns

An object if one exists. Otherwise, return None.

persist()#

Persists this cache to disk.

This function should be called after the cache has been populated. On the next run, the constructor will then pick up the index and return cached data.

put(key: bytes, value: object) bool#

Put a value into the cache using the provided key.

Parameters
  • key – The key under which value will be stored.

  • value – A pickable Python object to be stored.

Returns

True if the value was added to the cache, False if it was already cached.

liara.cmdline module#

class liara.cmdline.Environment#

Bases: object

The command line environment.

This provides access to global variables that are useful for command line commands, as well as a global liara instance.

property liara#
liara.cmdline.main()#

liara.config module#

liara.config.create_default_configuration() Dict[str, Any]#

Creates a dictionary with the default configuration.

liara.config.create_default_metadata() Dict[str, Any]#

Creates a dictionary with the default metadata.

liara.config.create_default_template_configuration() Dict[str, Any]#

Creates the default template configuration.

liara.feeds module#

class liara.feeds.FeedNode(path)#

Bases: liara.nodes.GeneratedNode

kind: liara.nodes.NodeKind#

The node kind, must be set in the constructor.

metadata: Dict[str, Any]#

Metadata associated with this node.

parent: Optional[Node]#

The parent node, if any.

path: pathlib.PurePosixPath#

The output path, relative to the page root.

All paths must start with /.

src: Optional[pathlib.Path]#

The full path to the source file.

This is an OS specific path object.

class liara.feeds.JsonFeedNode(path, site: liara.site.Site, *, collection='', limit=10)#

Bases: liara.feeds.FeedNode

A JSONFeed based feed.

content: Optional[Union[bytes, str]]#
generate()#

Generate the content of this node.

After this function has finished, self.content must be populated with the generated content.

kind: liara.nodes.NodeKind#

The node kind, must be set in the constructor.

metadata: Dict[str, Any]#

Metadata associated with this node.

parent: Optional[Node]#

The parent node, if any.

path: pathlib.PurePosixPath#

The output path, relative to the page root.

All paths must start with /.

src: Optional[pathlib.Path]#

The full path to the source file.

This is an OS specific path object.

class liara.feeds.RSSFeedNode(path, site: liara.site.Site, *, collection='', limit=10)#

Bases: liara.feeds.FeedNode

A RSS 2.0 based feed.

content: Optional[Union[bytes, str]]#
generate()#

Generate the content of this node.

After this function has finished, self.content must be populated with the generated content.

kind: liara.nodes.NodeKind#

The node kind, must be set in the constructor.

metadata: Dict[str, Any]#

Metadata associated with this node.

parent: Optional[Node]#

The parent node, if any.

path: pathlib.PurePosixPath#

The output path, relative to the page root.

All paths must start with /.

src: Optional[pathlib.Path]#

The full path to the source file.

This is an OS specific path object.

class liara.feeds.SitemapXmlFeedNode(path, site: liara.site.Site)#

Bases: liara.feeds.FeedNode

A Sitemap 0.90 based feed.

content: Optional[Union[bytes, str]]#
generate()#

Generate the content of this node.

After this function has finished, self.content must be populated with the generated content.

kind: liara.nodes.NodeKind#

The node kind, must be set in the constructor.

metadata: Dict[str, Any]#

Metadata associated with this node.

parent: Optional[Node]#

The parent node, if any.

path: pathlib.PurePosixPath#

The output path, relative to the page root.

All paths must start with /.

src: Optional[pathlib.Path]#

The full path to the source file.

This is an OS specific path object.

liara.md module#

class liara.md.HeadingLevelFixupExtension(**kwargs)#

Bases: markdown.extensions.Extension

Markdown extension for the HeadingLevelFixupProcessor.

extendMarkdown(md)#

Add the various processors and patterns to the Markdown Instance.

This method must be overridden by every extension.

Keyword arguments:

  • md: The Markdown instance.

  • md_globals: Global variables in the markdown module namespace.

class liara.md.HeadingLevelFixupProcessor(md=None)#

Bases: markdown.treeprocessors.Treeprocessor

This processor demotes headings by one level.

By default, Markdown starts headings with <h1>, but in general the title will be provided by a template. This processor replaces each heading with the next-lower heading, and adds a demoted class.

run(root)#

Subclasses of Treeprocessor should implement a run method, which takes a root ElementTree. This method can return another ElementTree object, and the existing root ElementTree will be replaced, or it can modify the current tree and return None.

liara.nodes module#

class liara.nodes.DataNode(src, path)#

Bases: liara.nodes.Node

A data node.

Data nodes consist of a dictionary. This can be used to store arbitrary data as part of a liara.site.Site, and make it available to templates (for instance, a menu structure could go into a data node.)

kind: liara.nodes.NodeKind#

The node kind, must be set in the constructor.

metadata: Dict[str, Any]#

Metadata associated with this node.

parent: Optional[liara.nodes.Node]#

The parent node, if any.

path: pathlib.PurePosixPath#

The output path, relative to the page root.

All paths must start with /.

src: Optional[pathlib.Path]#

The full path to the source file.

This is an OS specific path object.

class liara.nodes.DocumentNode(src, path, metadata_path=None)#

Bases: liara.nodes.Node

load()#

Load the content of this node.

publish(publisher: liara.nodes.Publisher) pathlib.Path#

Publish this node using the provided publisher.

reload()#

Reload this node from disk.

By default, this just forwards to _load().

set_fixups(*, load_fixups, process_fixups) None#

Set the fixups that should be applied to this document node. The fixups should be set before calling load().

Parameters
  • load_fixups – These functions will be executed before load() returns.

  • process_fixups – These functions will be executed before process() returns.

validate_metadata()#
class liara.nodes.DocumentNodeFactory(configuration)#

Bases: liara.nodes.NodeFactory[liara.nodes.DocumentNode]

A factory for document nodes.

class liara.nodes.FixupDateTimezone#

Bases: object

Set the timezone of the metadata['date'] field to the local timezone if no timezone has been set.

class liara.nodes.GeneratedNode(path, metadata: Optional[Dict] = None)#

Bases: liara.nodes.Node

generate() None#

Generate the content of this node.

After this function has finished, self.content must be populated with the generated content.

kind: liara.nodes.NodeKind#

The node kind, must be set in the constructor.

metadata: Dict[str, Any]#

Metadata associated with this node.

parent: Optional[liara.nodes.Node]#

The parent node, if any.

path: pathlib.PurePosixPath#

The output path, relative to the page root.

All paths must start with /.

publish(publisher: liara.nodes.Publisher)#

Publish this node using the provided publisher.

src: Optional[pathlib.Path]#

The full path to the source file.

This is an OS specific path object.

class liara.nodes.HtmlDocumentNode(src, path, metadata_path=None)#

Bases: liara.nodes.DocumentNode

A node representing a Html document.

process(cache: liara.cache.Cache)#

Some nodes – resources, documents, etc. need to be processed. As this can be a resource-intense process (for instance, it may require generating images), processing can cache results and has to be called separately instead of being executed as part of some other operation.

By convention this method should populate self.content.

class liara.nodes.IndexNode(path, metadata: Optional[Dict] = None)#

Bases: liara.nodes.Node

An index node.

Index nodes are created for every folder if there is no _index node present, and from indices. An index node can optionally contain a list of references, in case the referenced nodes by this index are not direct children of this node.

add_reference(node)#

Add a reference to an arbitrary node in the site.

publish(publisher) pathlib.Path#

Publish this node using the provided publisher.

references: List[liara.nodes.Node]#

Nodes referenced by this index node.

An index can not rely on using children as those have to be below the path of the parent node. The references list allows to reference nodes elsewhere in the site.

class liara.nodes.MarkdownDocumentNode(src, path, metadata_path=None)#

Bases: liara.nodes.DocumentNode

A node representing a Markdown document.

process(cache: liara.cache.Cache)#

Some nodes – resources, documents, etc. need to be processed. As this can be a resource-intense process (for instance, it may require generating images), processing can cache results and has to be called separately instead of being executed as part of some other operation.

By convention this method should populate self.content.

class liara.nodes.MetadataKind(value)#

Bases: enum.Enum

An enumeration.

Toml = 3#
Unknown = 1#
Yaml = 2#
class liara.nodes.Node#

Bases: object

add_child(child: liara.nodes.Node) None#

Add a new child to this node.

The path of the child node must be a sub-path of the current node path, with exactly one more component. I.e. if the current node path is /foo/bar, a node with path /foo/bar/baz can be added as a child, but /baz/ or /foo/bar/boo/baz would be invalid.

property children#

A list containing all direct children of this node.

get_child(name) Optional[liara.nodes.Node]#

Get a child of this node.

Returns

The child node or None if no such child exists.

get_children(*, recursive=False) Iterable[liara.nodes.Node]#

Get all children of this node.

This function differs from select_children() in two important ways:

  • It returns a list of Node instances and does not wrap it in a Query

  • It can enumerate all children recursively.

kind: liara.nodes.NodeKind#

The node kind, must be set in the constructor.

metadata: Dict[str, Any]#

Metadata associated with this node.

parent: Optional[liara.nodes.Node]#

The parent node, if any.

path: pathlib.PurePosixPath#

The output path, relative to the page root.

All paths must start with /.

process(cache: liara.cache.Cache) None#

Some nodes – resources, documents, etc. need to be processed. As this can be a resource-intense process (for instance, it may require generating images), processing can cache results and has to be called separately instead of being executed as part of some other operation.

By convention this method should populate self.content.

select_children()#

Select all children of this node and return them as a Query.

src: Optional[pathlib.Path]#

The full path to the source file.

This is an OS specific path object.

class liara.nodes.NodeFactory#

Bases: Generic[liara.nodes.T]

A generic factory for nodes, which builds nodes based on the file type.

create_node(suffix: str, src: pathlib.Path, path: pathlib.PurePosixPath, metadata_path: Optional[pathlib.Path] = None) liara.nodes.T#

Create a node using the provided parameters.

property known_types#
register_type(suffixes: Union[str, Iterable[str]], node_type: type) None#

Register a new node type.

Parameters
  • suffixes – Either one suffix, or a list of suffixes to be registered for this type. For instance, a node representing an image could be registered to [.jpg, .png].

  • node_type – The type of the node to be created.

class liara.nodes.NodeKind(value)#

Bases: enum.Enum

An enumeration.

Data = 4#
Document = 3#
Generated = 6#
Index = 2#
Resource = 1#
Static = 5#
class liara.nodes.Publisher#

Bases: object

A publisher produces the final output files, applying templates etc. as needed.

publish_document(document: liara.nodes.DocumentNode) pathlib.Path#

Publish a document node.

Returns

The path of the generated file.

publish_generated(generated: liara.nodes.GeneratedNode) pathlib.Path#

Publish a generated node.

Returns

The path of the generated file.

publish_index(index: liara.nodes.IndexNode) pathlib.Path#

Publish an index node.

Returns

The path of the generated file.

publish_resource(resource: liara.nodes.ResourceNode) pathlib.Path#

Publish a resource node.

Returns

The path of the generated file.

publish_static(static: liara.nodes.StaticNode) pathlib.Path#

Publish a static node.

Returns

The path of the generated file.

class liara.nodes.RedirectionNode(path: pathlib.PurePosixPath, dst: pathlib.PurePosixPath, *, base_url='')#

Bases: liara.nodes.GeneratedNode

A redirection node triggers a redirection to another page.

This node gets processed into a simple web site which tries to redirect using both <meta http-equiv="refresh"> and Javascript code setting window.location.

content: Optional[Union[bytes, str]]#
generate()#

Generate the content of this node.

After this function has finished, self.content must be populated with the generated content.

kind: liara.nodes.NodeKind#

The node kind, must be set in the constructor.

metadata: Dict[str, Any]#

Metadata associated with this node.

parent: Optional[liara.nodes.Node]#

The parent node, if any.

path: pathlib.PurePosixPath#

The output path, relative to the page root.

All paths must start with /.

src: Optional[pathlib.Path]#

The full path to the source file.

This is an OS specific path object.

class liara.nodes.ResourceNode(src, path, metadata_path=None)#

Bases: liara.nodes.Node

A resource node applies some process when creating the output.

This is useful if you have content where the source cannot be interpreted, and requires some process first before it becomes usable – for instance, SASS to CSS compilation.

kind: liara.nodes.NodeKind#

The node kind, must be set in the constructor.

metadata: Dict[str, Any]#

Metadata associated with this node.

parent: Optional[liara.nodes.Node]#

The parent node, if any.

path: pathlib.PurePosixPath#

The output path, relative to the page root.

All paths must start with /.

publish(publisher: liara.nodes.Publisher) pathlib.Path#

Publish this node using the provided publisher.

reload() None#
src: Optional[pathlib.Path]#

The full path to the source file.

This is an OS specific path object.

class liara.nodes.ResourceNodeFactory(configuration)#

Bases: liara.nodes.NodeFactory[liara.nodes.ResourceNode]

A factory for resource nodes.

class liara.nodes.SassResourceNode(src, path, metadata_path=None)#

Bases: liara.nodes.ResourceNode

This resource node compiles .sass and .scss files to CSS when built.

kind: liara.nodes.NodeKind#

The node kind, must be set in the constructor.

metadata: Dict[str, Any]#

Metadata associated with this node.

parent: Optional[liara.nodes.Node]#

The parent node, if any.

path: pathlib.PurePosixPath#

The output path, relative to the page root.

All paths must start with /.

process(cache: liara.cache.Cache)#

Some nodes – resources, documents, etc. need to be processed. As this can be a resource-intense process (for instance, it may require generating images), processing can cache results and has to be called separately instead of being executed as part of some other operation.

By convention this method should populate self.content.

reload() None#
set_compiler(compiler: Literal['cli', 'libsass'])#
src: Optional[pathlib.Path]#

The full path to the source file.

This is an OS specific path object.

class liara.nodes.StaticNode(src, path, metadata_path=None)#

Bases: liara.nodes.Node

A static data node.

Static nodes are suitable for large static data which never changes, for instance, binary files, videos, images etc.

property is_image#

Return True if this static file is pointing to an image.

kind: liara.nodes.NodeKind#

The node kind, must be set in the constructor.

metadata: Dict[str, Any]#

Metadata associated with this node.

parent: Optional[liara.nodes.Node]#

The parent node, if any.

path: pathlib.PurePosixPath#

The output path, relative to the page root.

All paths must start with /.

publish(publisher: liara.nodes.Publisher) pathlib.Path#

Publish this node using the provided publisher.

src: Optional[pathlib.Path]#

The full path to the source file.

This is an OS specific path object.

update_metadata() None#

Update metadata by deriving some metadata from the source file, if possible.

For static nodes pointing to images, this will create a new metadata field image_size and populate it with the image resolution.

class liara.nodes.ThumbnailNode(src, path, size)#

Bases: liara.nodes.ResourceNode

kind: liara.nodes.NodeKind#

The node kind, must be set in the constructor.

metadata: Dict[str, Any]#

Metadata associated with this node.

parent: Optional[liara.nodes.Node]#

The parent node, if any.

path: pathlib.PurePosixPath#

The output path, relative to the page root.

All paths must start with /.

process(cache: liara.cache.Cache)#

Some nodes – resources, documents, etc. need to be processed. As this can be a resource-intense process (for instance, it may require generating images), processing can cache results and has to be called separately instead of being executed as part of some other operation.

By convention this method should populate self.content.

src: Optional[pathlib.Path]#

The full path to the source file.

This is an OS specific path object.

liara.nodes.extract_metadata_content(text: str)#

Extract metadata and content.

Metadata is stored at the beginning of the file, separated using a metadata seperation marker, for instance:

+++
this_is_toml = True
+++

content

This function splits the provided text into metadata and actual content.

liara.nodes.fixup_date(document: liara.nodes.DocumentNode)#

If the date in the document is a string, try to parse it to produce a datetime object.

Replace relative links in the document with links relative to the site root.

liara.publish module#

class liara.publish.DefaultPublisher(output_path: pathlib.Path, site: liara.site.Site)#

Bases: liara.nodes.Publisher

publish_generated(generated: liara.nodes.GeneratedNode)#

Publish a generated node.

Returns

The path of the generated file.

publish_resource(resource: liara.nodes.ResourceNode)#

Publish a resource node.

Returns

The path of the generated file.

publish_static(static: liara.nodes.StaticNode)#

Publish a static node.

Returns

The path of the generated file.

class liara.publish.TemplatePublisher(output_path: pathlib.Path, site: liara.site.Site, template_repository: liara.template.TemplateRepository)#

Bases: liara.publish.DefaultPublisher

publish_document(document)#

Publish a document node.

Returns

The path of the generated file.

publish_index(index: liara.nodes.IndexNode)#

Publish an index node.

Returns

The path of the generated file.

liara.query module#

class liara.query.ExcludeFilter(pattern)#

Bases: liara.query.SelectionFilter

Filter items by a provided pattern. The pattern is matched against the path. If it matches, the item will be ignored.

match(node: liara.nodes.Node) bool#

Return True if the node should be kept, else False.

class liara.query.MetadataFilter(name, value=None)#

Bases: liara.query.SelectionFilter

Filter items which contain a specific metadata field and optionally check if that field matches the provided value.

match(node: liara.nodes.Node) bool#

Return True if the node should be kept, else False.

class liara.query.MetadataSorter(item: str, reverse=False, case_sensitive=False)#

Bases: liara.query.Sorter

Sort nodes by metadata.

get_key(item: liara.template.Page)#

Return the key to be used for sorting.

class liara.query.Query(nodes: Iterable[liara.nodes.Node])#

Bases: Iterable[Union[liara.nodes.Node, liara.template.Page]]

A query modifies a list of nodes, by sorting and filtering entries.

Index and document nodes will be wrapped in a Page instance. Everything else will be returned as a Node.

exclude(pattern) liara.query.Query#

Exclude nodes matching the provided regex pattern. The pattern will be applied to the full path.

limit(limit: int) liara.query.Query#

Limit this query to return at most limit results.

reversed() liara.query.Query#

Return the results of this query in reversed order.

sorted_by_date(*, reverse=False) liara.query.Query#

Sort the entries in this query by the metadata field date.

sorted_by_metadata(tag: str, *, reverse=False, case_sensitive=False) liara.query.Query#

Sort the entries in this query by the specified metadata field.

sorted_by_title(*, reverse=False) liara.query.Query#

Sort the entries in this query by the metadata field title.

with_metadata(name, value=None) liara.query.Query#

Limit this query to only include nodes which contain the specific metadata field.

Parameters

value – If value is provided, the field must exist and match the provided value.

with_tag(name) liara.query.Query#

Limit this query to only include nodes with a metadata field named tags which contains the specified tag name.

class liara.query.SelectionFilter#

Bases: object

Base class for query selection filters.

match(node: liara.nodes.Node) bool#

Return True if the node should be kept, else False.

class liara.query.Sorter(reverse=False)#

Bases: object

Base class for query sorters.

get_key(item)#

Return the key to be used for sorting.

property reverse#

Returns True if the sort order should be reversed.

class liara.query.TagFilter(name)#

Bases: liara.query.SelectionFilter

Filter items by a specific tag, this expects a metadata field named tags to be present, and that field must support checks for containment using in.

match(node: liara.nodes.Node) bool#

Return True if the node should be kept, else False.

liara.quickstart module#

liara.quickstart.generate(template_backend)#
liara.quickstart.generate_configs()#
liara.quickstart.generate_content()#
liara.quickstart.generate_css()#
liara.quickstart.generate_generator()#
liara.quickstart.generate_templates(backend)#
liara.quickstart.generate_theme(backend)#

liara.server module#

class liara.server.HttpServer(*, open_browser=True, port=8080)#

Bases: object

get_url()#
serve(site: liara.site.Site, template_repository: liara.template.TemplateRepository, configuration, cache: liara.cache.Cache)#

Serve the site with just-in-time processing.

This does not build the whole site up-front, but rather builds nodes on demand. Nodes requiring templates are rebuilt from scratch every time to ensure they’re up-to-date. Adding/removing nodes while serving will break the server, as it will not get notified and re-discover content.

liara.signals module#

See Processing order for an overview of the processing stages.

liara.signals.content_filtered#

Raised when content has been removed due to a filter.

This signal is raised during the content discovery stage.

Parameters
liara.signals.content_added#

Raised when a content node was successfully added.

This signal is raised during the content discovery stage. It is not raised for nodes that have been filtered.

Parameters

node (liara.nodes.Node) – the node that was created

liara.signals.commandline_prepared#

Raised when the command line parsing environment was prepared.

Parameters

cli (click.group) – The command line group to add commands to.

liara.signals.content_discovered#

Raised after all content has been discovered.

Parameters

site (liara.site.Site) – the site instance

liara.signals.documents_processed#

Raised after all documents have been processed.

Parameters

site (liara.site.Site) – the site instance

Processing includes the conversion from Markdown to HTML.

liara.signals.document_loaded#

Raised after a document has been loaded.

This signal is raised during the content discovery stage.

Parameters

When this signal is raised, the content has been loaded, but no templates etc. have been applied to the document yet.

liara.site module#

class liara.site.Collection(site, pattern, order_by: Optional[List[str]] = None)#

Bases: object

A collection is a set of nodes. Collections can be ordered, which allows for next/previous queries.

get_next(node)#

Get the next node in this collection with regard to the specified order, or None if this is the last node.

get_previous(node)#

Get the previous node in this collection with regard to the specified order, or None if this is the first node.

property nodes#

Get the (sorted) nodes in this collection.

class liara.site.ContentFilter#

Bases: object

Content filters can filter out nodes based on various criteria.

apply(node: liara.nodes.Node) bool#

Return True if the node should be kept, and False otherwise.

property name: str#
property reason: str#

Return a reason why this filter applied.

class liara.site.ContentFilterFactory#

Bases: object

create_filter(name: str) liara.site.ContentFilter#
class liara.site.DateFilter#

Bases: liara.site.ContentFilter

Filter content based on the metadata field date.

If the date is in the future, the node will be filtered.

apply(node: liara.nodes.Node) bool#

Return True if the node should be kept, and False otherwise.

property name#
property reason#

Return a reason why this filter applied.

class liara.site.Index(collection: liara.site.Collection, path: str, group_by: Optional[List] = None, *, create_top_level_index=False)#

Bases: object

An index into a collection, which provides an index structure.

The index structure requires a grouping schema – for instance, all nodes containing some tag can get grouped under one index node.

create_nodes(site: liara.site.Site)#

Create the index nodes inside the specified site.

class liara.site.Site#

Bases: object

This class manages to all site content.

add_data(node: liara.nodes.DataNode) None#

Add a data node to this site.

add_document(node: liara.nodes.DocumentNode) None#

Add a document to this site.

add_generated(node: liara.nodes.GeneratedNode) None#

Add a generated node to this site.

add_index(node: liara.nodes.IndexNode) None#

Add an index node to this site.

add_resource(node: liara.nodes.ResourceNode) None#

Add a resource to this site.

add_static(node: liara.nodes.StaticNode) None#

Add a static node to this site.

create_collections(collections)#

Create collections.

create_indices(indices)#

Create indices.

This creates links between parents/children.

This is a separate step so it can be executed after merging nodes from multiple sources, for instance themes. It is safe to call this function multiple times to create new links; nodes which already have a parent are automatically skipped.

create_thumbnails(thumbnail_definition)#

Create thumbnails.

Based on the thumbnail definition – which is assumed to be a dictionary containing the suffix and the desired size – this function iterates over all static nodes that contain images, and creates new thumbnail nodes as required.

data: List[liara.nodes.DataNode]#

The list of all data nodes in this site.

documents: List[liara.nodes.DocumentNode]#

The list of all document nodes in this site.

property filtered_content: Dict[pathlib.PurePosixPath, str]#

Return which node paths got filtered and due to which filter.

generated: List[liara.nodes.GeneratedNode]#

The list of all generated nodes in this site.

get_collection(collection: str) liara.site.Collection#

Get a collection.

get_next_in_collection(collection: str, node: liara.nodes.Node) Optional[liara.nodes.Node]#

Get the next node in a collection.

get_node(path: pathlib.PurePosixPath) Optional[liara.nodes.Node]#

Get a node based on the URL, or None if no such node exists.

get_previous_in_collection(collection: str, node: liara.nodes.Node) Optional[liara.nodes.Node]#

Get the previous node in a collection.

indices: List[liara.nodes.IndexNode]#

The list of all index nodes in this site.

metadata: Dict[str, Any]#

Metadata describing this site.

property nodes: ValuesView[liara.nodes.Node]#

The list of all nodes in this site.

register_content_filter(content_filter: liara.site.ContentFilter)#

Register a new content filter.

resources: List[liara.nodes.ResourceNode]#

The list of all resources nodes in this site.

select(query: str) Iterable[liara.nodes.Node]#

Select nodes from this site.

The query string may contain * to list all direct children of a node, and ** to recursively enumerate nodes. Partial matches using *foo are not supported. See URL patterns for details.

set_metadata(metadata: Dict[str, Any]) None#

Set the metadata for this site.

This overrides any previously set metadata. Metadata is accessible via the metadata attribute.

set_metadata_item(key: str, value: Any) None#

Set a single entry in the metadata for this site.

This can be used to override individual metadata items.

static: List[liara.nodes.StaticNode]#

The list of all static nodes in this site.

property urls: KeysView[pathlib.PurePosixPath]#

The list of all registered URLs.

class liara.site.StatusFilter#

Bases: liara.site.ContentFilter

Filter content based on the metadata field status.

If status is set to private, the node will be filtered. The comparison is case-insensitive.

apply(node: liara.nodes.Node) bool#

Return True if the node should be kept, and False otherwise.

property name#
property reason#

Return a reason why this filter applied.

liara.template module#

class liara.template.Jinja2Template(template)#

Bases: liara.template.Template

render(**kwargs) str#
class liara.template.Jinja2TemplateRepository(paths: Dict[str, str], path: pathlib.Path, cache: Optional[liara.cache.Cache] = None, *, options: Optional[Dict[str, Any]] = None)#

Bases: liara.template.TemplateRepository

Jinja2 based template repository.

find_template(url: pathlib.PurePosixPath, site: Site) liara.template.Template#
class liara.template.MakoTemplate(template)#

Bases: liara.template.Template

render(**kwargs) str#
class liara.template.MakoTemplateRepository(paths: Dict[str, str], path: pathlib.Path)#

Bases: liara.template.TemplateRepository

find_template(url: pathlib.PurePosixPath, site: Site) liara.template.Template#
class liara.template.Page(node)#

Bases: object

A wrapper around DocumentNode and IndexNode for use inside templates.

Templates only get applied to those node types, and the Page class provides convenience accessors while hiding the underlying node from template code.

property content: str#

Provides the content of this page.

property meta: Dict[str, Any]#

Provides the metadata associated with this page.

Deprecated since version 2.1.2: Use metadata instead.

property metadata: Dict[str, Any]#

Provides the metadata associated with this page.

New in version 2.1.2.

property references: Query#

Provides the list of referenced nodes by this page.

This can be only used if the current page is an IndexNode, in all other cases this will fail. For index nodes, this will return the list of references as a Query instance.

property url: str#

Provides the current path of this page.

class liara.template.SiteTemplateProxy(site: Site)#

Bases: object

A wrapper around Site for use inside templates.

property data: Dict[str, Any]#

Get the union of all liara.nodes.DataNode instances in this site.

get_collection(collection: str) Query#

Get a collection in form of a liara.query.Query for further filtering/sorting.

get_next_in_collection(collection: str, page: liara.template.Page) Optional[liara.template.Page]#

Given a collection and a page, return the next page in this collection or None if this is the last page.

get_page_by_url(url) Optional[liara.template.Page]#

Return a page by URL. If the page cannot be found, return None.

get_previous_in_collection(collection: str, page: liara.template.Page) Optional[liara.template.Page]#

Given a collection and a page, return the previous page in this collection or None if this is the first page.

property metadata: Dict[str, Any]#

Provide access to the metadata of this site.

select(query) Query#

Run a query on this site.

class liara.template.Template#

Bases: object

render(**kwargs)#
class liara.template.TemplateRepository(paths: Dict[str, str])#

Bases: object

find_template(url: pathlib.PurePosixPath, site: Site) liara.template.Template#
update_paths(paths: Dict[str, str])#

liara.util module#

class liara.util.FilesystemWalker(ignore_files: Optional[List[str]] = None)#

Bases: object

walk(path: pathlib.Path)#

Walk a directory recursively.

This is quite similar to os.walk, but with two major differences:

  • Files matching the ignore_files pattern are ignored.

  • The dirnames part of the tuple is omitted

liara.util.add_suffix(path: pathlib.Path, suffix)#

Add a suffix to a path.

This differs from with_suffix by adding a suffix without changing the extension, i.e. adding en to foo.baz will produce foo.en.baz.

liara.util.create_slug(s: str) str#

Convert a plain string into a slug.

A slug is suitable for use as a URL. For instance, passing A new world to this function will return a-new-world.

liara.util.flatten_dictionary(d, sep='.', parent_key=None, *, ignore_keys: Optional[set] = None)#

Flatten a nested dictionary. This uses the separator to combine keys together, so a dictionary access like ['a']['b'] with a separator '.' turns into 'a.b'.

If ignore_keys is set, it must be a list of fully flattened key names at which the flattening should stop. For instance, if a dictionary {'a': {'b': {'c': 1}}} is provided, and ignore_keys is {'a.b'}, then a.b will not get flattened further, so a.b will contain a dictionary with {'c': 1}.

liara.util.local_now() datetime.datetime#

Get the current date/time in the local time zone.

This is equivalent to datetime.datetime.now(), except it returns a timestamp which has tzinfo set to the local timezone.

This can be overridden using set_local_now to build the page at a different point in time.

liara.util.pairwise(iterable)#

For a list s, return pairs for consecutive entries. For example, a list s0, s1, etc. will produce (s0,s1), (s1,s2), ... and so on.

See: https://docs.python.org/3/library/itertools.html#recipes.

liara.util.readtime(wordcount: int, words_per_minute=300)#

Given a number of words, estimate the time it would take to read them.

Returns

The time in minutes if it’s more than 1, otherwise 1.

liara.util.set_local_now(dt: datetime.datetime)#

Override “now” to allow previewing the page at a different point in time.

liara.yaml module#

liara.yaml.dump_yaml(data, stream: Optional[IO] = None)#

Dump an object to Yaml.

This is a helper function which tries to use the fast CDumper implementation and falls back to the native Python version on failure.

liara.yaml.load_yaml(s: Union[bytes, IO, IO[bytes], str, IO[str]])#

Load a Yaml document.

This is a helper function which tries to use the fast CLoader implementation and falls back to the native Python version on failure.

Module contents#

class liara.Liara(configuration: Optional[Union[str, IO, IO[bytes], IO[str]]] = None, *, configuration_overrides: Optional[Dict] = None)#

Main entry point for Liara. This class handles all the state required to process and build a site.

build(discover_content=True)#

Build the site.

Parameters

discover_content (bool) – If True, discover_content() will be called first.

create_document(t)#

Create a new document using a generator.

discover_content() liara.site.Site#

Discover all content and build the liara.site.Site instance.

serve(*, open_browser=True, port=8080, cache=True)#

Serve the current site using a local webserver.