Commit graph

73 commits

Author SHA1 Message Date
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
mntn
0ac0476e62
Integrate sprig v3 for improved templating (#9) 2021-08-16 20:29:13 +05:00
Timur Demin
aadb650f1f
Merge pull request #8 from tdemin/bugfix/blockquote
Fix #5
2021-08-13 17:59:56 +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
36922b6e95
Keep line breaks in blockquotes
This makes the renderer preserve existing line breaks in blockquotes,
provided they do not split paragraphs. Some clients/sites may use this
to form semantic around line breaks (for instance, for poems).

See #5.
2021-08-13 09:50:21 +05:00
Timur Demin
35977a721c
Add golangci-lint config
Somehow the config managed to stay in .gitignore a while, causing
CI checks to fail.
2021-08-13 09:08:57 +05:00
Timur Demin
d8870403fe
Add golangci-lint config
Somehow the config managed to stay in .gitignore a while, causing
CI checks to fail.
2021-08-13 09:08:45 +05:00
Timur Demin
adcf0ac73e
Make linter happy
This removes some of the leftovers of older logic in cmd/gmnhg.
2021-08-13 09:01:16 +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
845bfa7cb2
Fix panic on empty blockquotes
While renderer previously assumed there would always be a single
paragraph inside the blockquote, there sometimes can be either more or
none.

See #5.
2021-08-13 08:52:52 +05:00
Timur Demin
e5d791165d Implement tables rendering
This adds support for Markdown table rendering with
github.com/olekukonko/tablewriter. Tables are rendered as ASCII text
in a preformatted text block. Cells are hard-aligned with spaces.
tablewriter options are not yet configurable, although they should be.
For now, extra formatting inside tables is omitted.

Fixes #2.
2021-08-09 20:13:10 +05:00
Timur Demin
0be85fc7f9
Handle H4-H6 in accordance with Gemini spec
Unlike Markdown, which has 6 levels of headings, Gemini spec (p. 5.5.1)
only allows up to 3 shebang characters before a space. This adds an extra
space before levels 4-6 in order to comply with the spec.

Fixes #1.
2021-08-09 12:00:48 +05:00
Timur Demin
2ea0b7d5fa
Update to Go v1.16 2021-08-01 04:15:32 +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
7eaf6b7c8a
Fix #8
This fixes trailing newlines at the end of Gemtext being left.
2020-12-12 16:30:25 +05:00
Timur Demin
d89c4b5e50
Reword RenderMarkdown docstring 2020-12-12 14:06:22 +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
30a5d407e2
Add Docker build files 2020-11-21 23:19:34 +05:00
Timur Demin
26fcc06075
Release v0.1.0 2020-11-20 16:35:07 +05:00
Timur Demin
2d55d4f1e6
Add CI config and pkg.go.dev link 2020-11-20 16:20:06 +05:00
Timur Demin
2211c5ffdd
Prevent rendering _index.gmi.md as posts 2020-11-20 04:17:20 +05:00
Timur Demin
1f5257ac90
Fix rendering of links-only paragraphs 2020-11-20 03:59:45 +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
b660e0b1da
Rewrite README with info on gmnhg 2020-11-19 03:27:03 +05:00
Timur Demin
8c1a9a36da
Refactor rendering code
This refactoring simplifies some originally quirky parts of rendering
code while also adding support for rendering emphasized text (handled by
the same routine the ordinary text already is).
2020-11-19 03:09:28 +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
35b4168935
Comply with Gemini spec p. 5.4.1
This part of spec says soft text wrapping is preferred to hard wrapping,
to comply with that we replace the newlines in raw Markdown text with
spaces.
2020-11-11 23:21:17 +05:00