Commit graph

106 commits

Author SHA1 Message Date
Nimble 98b9a407a5 modified gitignored for bin and build script 2023-02-12 15:34:31 -06:00
Timur Demin 6f43f76247
Allow using _index.md on no _index.gmi.md
This makes gmnhg use _index.md as directory / top-level index page
content source in case _index.gmi.md is not present.

As the renderer has matured a lot (namely lists of links are now handled
a lot better), this should allow writing almost zero content specific to
gmnhg.

The docs are updated accordingly.
2022-12-04 14:24:09 +05:00
Timur Demin e0754ac405
Fix a minor docs typo 2022-03-27 14:16:21 +05:00
Timur Demin 263e7eea39
Fix quotes in conditionals 2022-03-21 01:14:00 +05:00
Timur Demin f8a310288a
Provide more metadata with images
This assigns the OCI spec labels to images pushed to GHCR, and enables
image users to see current tool version instead of just v0+HEAD.
2022-03-20 01:13:42 +05:00
Timur Demin 6f3720a4ae
Reorganize GHCR workflows
This removes the manual build workflow, unifying it with the automatic
GHCR release workflow and ensuring Docker images are autobuilt.
2022-03-20 00:03:33 +05:00
Timur Demin a1521884ef
Use fully-qualified base image names
This makes the Dockerfile use FQDNs for registry names as recommended by
Podman and other OCI-compatible container solutions.
2022-03-19 14:38:04 +05:00
Timur Demin c153a6ef75
Bump Go / golangci-lint versions used during PR testing 2022-03-19 14:30:04 +05:00
Timur Demin 0f2e3ca4ea
Reformat goreleaser config for better YAML consistency 2022-03-19 14:27:38 +05:00
Timur Demin f507bd3461
Update dependencies 2022-03-19 14:25:14 +05:00
Timur Demin 13bace70d2
Bump base image versions 2022-03-19 14:13:30 +05:00
Timur Demin 5f755e4fa3
Encode link URIs before rendering into Gemtext
This makes gmnhg encode link destinations before rendering them into
Gemtext according to RFC 3986. This particularly fixes spaces in links.

Invalid URIs will skipped from rendering entirely.

Fixes #49.
2022-01-14 00:19:40 +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 aec3b10041
Split up renderer code into separate files
This moves various components of internal/renderer into
separate files in the package, and adds doc.go for godoc.
2021-11-02 01:15:19 +05:00
Timur Demin 7da783e853
Make workflow runs dispatchable manually 2021-10-03 11:35:02 +05:00
Timur Demin bc7e8b6858
Prune useless goreleaser settings 2021-10-03 11:05:32 +05:00
mntn ddb3943359
Strip HTML tags but keep content while rendering
This makes the renderer print the content of informational
HTML tags while stripping the tags themselves.

Tags like script, iframe, style, etc, which are unlikely to
ever hold presentable content, are exempt from this, and
their content is skipped from rendering as well as the tags
themselves.

<br>, a hard-break tag, is supported as a Markdown
hard-break replacement (the two spaces before newline).

This also adds tests for this behavior inside general_text.md.

Fixes #6, a longstanding issue with inline HTML in
blockquotes.
2021-10-02 15:07:46 +05:00
Timur Demin fc76187e13
Implement renderer test suite
This implements a Markdown / Gemtext suite, testing the entire renderer
at complex Markdown documents, containing the entirety of current
Markdown features accessible with gmnhg. The test suite can be expanded
by adding a pair of .md/.gmi files.

Minor bug fixes in JSON/Org metadata parsing where bugs were detected
with the test suite are also included in this patch.

Fixes #13.
2021-09-30 18:01:46 +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 5e84953103
Update README.md 2021-09-17 23:15:20 +05:00
Timur Demin 8135d1e0b3
Update heading renderer to latest Gemini spec
Gemini spec p. 5.5.1 used to only allow up to three #-s in a heading
before requiring a mandatory space. It changed to an optional space in
recent updates, allowing to no longer pad Markdown H4-H6.

As clients treat everything after ### a title continuation, the renderer
will now insert H4-H6 verbatim; the end-user behavior doesn't change as
extra space means nothing for a Gemtext renderer displaying the title in
a special way.

Relates to #1.

PS: Gemini spec doesn't appear to be properly versioned, saying the
latest version is 0.14.3, 2020-11-29. The discussion on #1 clearly shows
it used to be different a while ago.
2021-09-17 23:02:46 +05:00
Timur Demin 45180f9315
Remove an outdated TODO 2021-09-17 22:55:44 +05:00
Timur Demin fa5b4cb180
Bump dependencies update 2021-09-17 22:42:45 +05:00
Timur Demin c476976b27
Bump Go and external deps versions 2021-09-17 22:42:28 +05:00
Timur Demin 7e19930b1b
Add missing copyright headers 2021-09-17 22:37:10 +05:00
Timur Demin b01f5093ce
Add Go Report Card to README 2021-09-17 22:35:40 +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
Timur Demin 492deddf06
Add release badge to README 2021-09-09 17:48:31 +05:00
Timur Demin 463868f10d
Use no dedicated secrets in GitHub Actions 2021-09-09 17:42:58 +05:00
Timur Demin bcc3d8b730
Implement a generic links & text extractor
Before this, links would only be scraped from paragraphs and
rendered as a block after parent paragraph. This replaces this logic
with a generic links extractor that would recursively collect every link
from any parent node, including footnotes, blockquotes, and lists.

The renderer splits links block in three separate blocks, one
containing footnotes, the second containing images, and the third
links. Blocks are separated by a single line break.

This also makes the renderer skip link-only lists from rendering,
making them behave like links-only paragraphs (which are already
rendered as a series of consecutive links). The old behavior of
extracting links from links-only paragraphs (where the paragraph
itself is treated as just a set of links) remains, and can be still used.

The text extraction is also now unified across headings, paragraphs,
table headings, blockquotes, and other elements where it was used.
This fixes a number of bugs (like panicking on links inside headings)
and shortcomings where renderer would render text differently
based on container element type.

Fixes #17 and #23.
2021-09-03 20:48:32 +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 ea62886fca
Implement footnotes support
This adds footnotes support, with rendering their text
after their parent paragraph. Footnotes are limited to
just one line by gomarkdown.

Fixes #16.
2021-08-31 10:12:39 +05:00
mntn 86faf01552
Add support for HR and super/sub-script
This makes the renderer write --- in place of
Markdown/HTML horizontal lines, and render super/subscript
as ^(superscript) and _{subscript} respectively.
2021-08-29 19:28:43 +05:00
mntn ba767bc91f
Fix definition list rendering for multiple terms
The original implementation would incorrectly prefix the rest of the terms
if there were multiple terms going after each other (forming a list
themselves). 

Fixup f17a959fe2.
2021-08-28 09:33:55 +05:00
Timur Demin f17a959fe2
Implement definition lists support
This adds the support of Markdown definition lists. The first item in
such lists (the definition itself) is printed without an item prefix.

Fixes #15.
2021-08-27 15:42:00 +05:00
Timur Demin df6c035c7e
Refactor type detection code 2021-08-23 22:09:41 +03:00
Timur Demin 688d88d72b
Make the Go compiler calculate renderer flags
This makes the Go compiler automatically calculate renderer
flags bitmask values by putting 1 << iota as the first meaningful flag.
This has a downside of having the first flag always meaning 2, and not
1, whereas WithMetadata already meaned 1, therefore this is a breaking
change.
2021-08-22 23:05:49 +03:00
Timur Demin c872e012e2
Enable gomarkdown's NoEmptyLineBeforeBlock rule
This changes gomarkdown parser behavior to allow code blocks, lists, etc
to come after other blocks (like paragraphs) and get processed as
independent blocks without a separate newline (putting gomarkdown in
charge to decide whether a new block is started).

This is a breaking change as this affects how some existing Markdown
source might get rendered. Nonetheless, this is probably the expected
default by most users. This has no configurable switch yet.

See #14.
2021-08-22 22:51:52 +03: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
mntn 5265bb6a25 Print delimiters around unsupported formatted elements 2021-08-22 14:31:39 +03:00
mntn d3e8276e6e Add info string for fenced code blocks 2021-08-22 14:31:39 +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