diff options
| author | Shulhan <ms@kilabit.info> | 2023-05-14 17:06:21 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-05-14 17:13:56 +0700 |
| commit | fad7cd21134a4cac75f876bce866830c35042f8e (patch) | |
| tree | dd55dd5c6edf2b5bfb8f0bf7d6e1cb12b15712eb /filehtml.go | |
| parent | c109a3dd026cf6fbdc147d5a2c17535569d8964d (diff) | |
| download | ciigo-fad7cd21134a4cac75f876bce866830c35042f8e.tar.xz | |
all: bring back support for Markdown
I use two remote repositories: GitHub and SourceHut.
GitHub support rendering README using asciidoc while SourceHut not.
This cause the repository that use README.adoc rendered as text in
SourceHut which make the repository page less readable.
Also, the pkg.go.dev now render README but only support Markdown.
Since we cannot control the SourceHut and go.dev, the only option is
to support converting Markdown in ciigo so I can write README using
Markdown and the rest of documentation using Asciidoc.
Diffstat (limited to 'filehtml.go')
| -rw-r--r-- | filehtml.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/filehtml.go b/filehtml.go index 4c3ea1c..235329e 100644 --- a/filehtml.go +++ b/filehtml.go @@ -4,6 +4,7 @@ package ciigo import ( + "fmt" "html/template" "strings" @@ -12,6 +13,7 @@ import ( const ( metadataStylesheet = `stylesheet` + metadataTitle = `title` ) // fileHtml represent an HTML metadata for header and its body. @@ -58,3 +60,37 @@ func (fhtml *fileHtml) unpackAdocMetadata(doc *asciidoctor.Document) { fhtml.EmbeddedCSS = embeddedCSS() } } + +func (fhtml *fileHtml) unpackMarkdownMetadata(metadata map[string]any) { + var ( + key string + val any + vstr string + ok bool + ) + + fhtml.Styles = fhtml.Styles[:0] + + for key, val = range metadata { + vstr, ok = val.(string) + if !ok { + vstr = fmt.Sprintf(`%s`, val) + } + + key = strings.ToLower(key) + switch key { + case metadataStylesheet: + fhtml.Styles = append(fhtml.Styles, vstr) + case metadataTitle: + fhtml.Title = vstr + default: + // Metadata `author_names`, `description`, + // `generator`, and `keywords` goes here. + fhtml.Metadata[key] = vstr + } + } + + if len(fhtml.Styles) == 0 { + fhtml.EmbeddedCSS = embeddedCSS() + } +} |
