Commit graph

36 commits

Author SHA1 Message Date
Timur Demin
e0754ac405
Fix a minor docs typo 2022-03-27 14:16:21 +05:00
Timur Demin
62d762a8c7
Pass .Metadata to directory index pages
This makes gmnhg pass .Metadata while rendering directory and top-level
indexes, allowing the user to use page metadata keys for things like
page title instead of resorting to formatting with the page content.

.Metadata is omitted while rendering RSS indexes for now, because it
doesn't seem to make much sense for it to be there.

Fixes #39.
2021-12-25 21:55:31 +05:00
mntn
f858ec383b
Allow non-latin characters in paths
This makes gmnhg use [\pL\d\-_] to match paths instead of \w,
allowing letter characters from any Unicode language in file
paths.

Fixes #48.
2021-12-25 21:51:26 +05:00
Timur Demin
ee8e58ffb9
Rewrap godoc comment at 72 characters 2021-11-18 23:29:07 +05:00
mntn
c80b72613d
Clean up templates and unify template metadata
This exposes more site-specific information to templates. Top-level
_index(.gmi).md is now treated by the templating code the same
way per-directory indices are (which introduces a breaking change:
top-level posts now receive .Posts instead of .PostData).

Web-specific metadata is now removed from the RSS.

This makes gmnhg usable out of the box to generate a reasonable
site with zero configuration even with pages with no metadata.
2021-09-22 02:29:14 +05:00
mntn
372646033c
Use same variable names as Hugo
This makes gmnhg use settings from Hugo by default, allowing
to override variables in a separate gmnhg section.

Currently the templates use baseUrl, title, languageCode and
copyright.

Fixes #29.
2021-09-20 22:20:40 +05:00
mntn
3110ac629c
Update default templates to use new metadata
This updates default gmnhg templates to new field names
after changes introduced after recent major refactoring.

Fixup 9778ada128.
2021-09-20 03:19:29 +05:00
Timur Demin
9778ada128
Parse metadata in all Hugo formats
This makes gmnhg parse TOML/YAML/JSON/org-mode front matter in Hugo posts.

This also makes the library no longer render metadata in posts, removing
the API to do so. The metadata parsing code itself moves to
internal/gmnhg.

As the library no longer has a preset to include metadata in rendered
document, md2gmn will from now on silently discard front matter if it
encounters any.

Fixes #28. Unblocks #13.
2021-09-17 22:34:03 +05:00
mntn
2de6e634d6
Add RSS support
This implements RSS timeline generation in gmnhg.

RSS is generated both for the whole site, and for the content
directories as an rss.xml file inside these directories.

RSS requires the absolute URI to the article. For this to work,
a geminiBaseURL setting is required to be set in the Hugo
configuration file (config.toml/json/yaml).

RSS template can be ovewritten on the site-wide /
directory-wise basis; see godoc on how to do this.

As there's no discovery method of an RSS timeline in Gemini,
the users are expected to put a link to rss.xml on their site
where necessary.
2021-09-12 16:26:33 +05:00
mntn
3a86f0f7e6
Support Hugo headless page bundle leaf nodes
With Hugo, a page bundle can be skipped from rendering if
it specifies headless = true in its front matter. This makes
gmnhg properly skip these pages from rendering.

Fixes #11.
2021-09-01 00:06:23 +05:00
Timur Demin
4511e4280f
Update & rewrap gmnhg docs 2021-08-22 17:52:56 +03:00
Timur Demin
b4ae1981d6
Implement sort / sortRev in templates
This adds generic sort / sortRev functions for use in gmnhg templates
which use sort.Sort to sort anything that implements sort.Interface
(which includes lists of posts).

The existing sortPosts function that used to sort posts in reverse order
becomes an alias to sortRev for backwards compatibility.
2021-08-22 17:52:19 +03:00
Timur Demin
7fba4182e1
Run gofmt on templates.go 2021-08-22 15:34:30 +03:00
Timur Demin
8cdbc778e5
Run gofmt on cmd/gmnhg
This fixes minor formatting issues from c2f2386.
2021-08-17 23:01:13 +05:00
mntn
c2f2386a3d
Add support for branch and leaf bundles
This patch adds support for Hugo's branch and leaf bundles: https://gohugo.io/content-management/page-bundles/

Content directories can now have nested subdirectories, and content from each level will be converted to Gemini. If a subdirectory has a file named index.md (or any index.* file per the footnote on the Hugo page) then it becomes a leaf bundle. For leaf bundles, only the generated index.gmi file will be passed up to parent directories as a page. The rest will be treated as "resources" that are not normally visible to pages in parent folders.

Each parent _index.md receives a list of pages from all nested subdirectories (except for the aforementioned leaf resource pages). This allows for content "rollup" pages. For instance, /series could show all pages under /series/first-season and /series/second-season, while allowing each subfolder to have its own more limited index. This also allows for "clean" URLs, as leaf bundles can be used to make pages that are basically just an index.md page under a named folder. You can then use the trimSuffix function (from sprig) in your gotmpl templates to clean up any links, by stripping "/index.md".

This patch also adds the copying of non-Markdown resource files from content directories, so that bundled resources can be pulled in. Theoretically if someone puts carefully named .gmi files in their content folder then this could cause a name collision, but you'd almost have to try to make that happen, so I didn't put in any checks for it. If this happens then any generated files with the same name are simply overwritten, so there's no serious harm done.

Hugo's leaf bundles support a special front matter attribute, "headless", which if set to true will cause the index.md file to be "invisible" and it will not be passed up to the parent. This is not currently implemented.
2021-08-17 22:59:11 +05:00
mntn
0ac0476e62
Integrate sprig v3 for improved templating (#9) 2021-08-16 20:29:13 +05:00
Timur Demin
af021e9ae1
Allow for YAML/JSON Hugo config
Hugo allows storing config in either config.toml, config.json, or
config.yaml, while gmnhg previously only checked for config.toml.

Fixes #7.
2021-08-13 10:12:00 +05:00
Timur Demin
a35536c8be
Make linter happy
This removes some of the leftovers of older logic in cmd/gmnhg.
2021-08-13 09:00:37 +05:00
Timur Demin
66b2f83a88
Migrate to GitHub 2021-08-01 04:11:04 +05:00
Timur Demin
d182adba8c
Add version display 2021-02-19 16:57:16 +05:00
Timur Demin
ae794d9d59
Comment on sortPosts behaviour 2021-02-19 16:47:14 +05:00
Timur Demin
cf65fcc5c3
Fix gmnhg crash on non-existent static/ 2021-01-23 00:25:02 +05:00
Timur Demin
47e056f253
Refactor RenderMarkdown signature
This makes the function accept a bitmask instead of a single flag. This
is a breaking change.
2020-12-12 14:03:29 +05:00
Timur Demin
2211c5ffdd
Prevent rendering _index.gmi.md as posts 2020-11-20 04:17:20 +05:00
Timur Demin
421a40783c
Use gmnhg/ instead of layouts/gmnhg/
Unfortunately, Hugo will try to parse every template file in layouts/,
so we have to reside somewhere else.
2020-11-19 21:16:36 +05:00
Timur Demin
9d16372487
Implement sourcing _index.md content
Fixes #5. The Markdown content is sourced from _index.gmi.md so we don't
interfere with native Web content.
2020-11-19 21:12:59 +05:00
Timur Demin
0a62f8142c
Fix single template not being sourced 2020-11-19 04:30:37 +05:00
Timur Demin
6859f3d57c
Fix panic on draft posts 2020-11-19 03:32:55 +05:00
Timur Demin
1a0e61dc3f
Implement gmnhg
gmnhg is the new program that generates a Gemini site from Hugo site
content. It reads its input from content/, static/, and layouts/gmnhg/.
Its output by default goes to output/.

More doc is available in the program doc header.
2020-11-18 22:23:31 +05:00
Timur Demin
8226a20880
Change API for simpler use by gmnhg 2020-11-11 23:21:18 +05:00
Timur Demin
b181afc5f1
Add YAML front matter parsing support
Fixes #1. Only a subset of Hugo front matter props are supported, namely
title/date.
2020-11-11 23:21:17 +05:00
Timur Demin
32ec381d73
Add README and license code under GPLv3 2020-11-11 23:21:16 +05:00
Timur Demin
4d80d36f00
Provide a public API
This also introduces a simple program, md2gmn, that is meant for testing
the renderer on Markdown files. Nonetheless, it can be used as
a standalone tool as well.
2020-11-11 23:20:52 +05:00
Timur Demin
b2a941bdb6
Add preformatted text block support 2020-11-08 01:07:53 +05:00
Timur Demin
98d6ff6d5f
Add lists and subsequent link paras to test text 2020-11-08 00:06:43 +05:00
Timur Demin
85b0ef51b3
Add the latest code 2020-11-06 13:47:02 +05:00