content2html

package module
v0.0.0-...-8f1bf38 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

README

content2html

Package content2html implements a very simple HTML templating system for documents. It applies an html/template and fills it with the body text from an input file, discovering the document's <title> from its 1st <h1>. This way, you can write plain HTML, and generate complete documents with templatized boilerplate.

Documentation

Overview

Package content2html implements a very simple HTML templating system for documents. It applies an html/template and fills it with the body text from an input file, discovering the document's <title> from its 1st <h1>. This way, you can write plain HTML, and generate complete documents with templatized boilerplate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateDocument

func GenerateDocument(t *template.Template, content []byte, w io.Writer) error

GenerateDocument executes template t with the document content, writing to w. It completes [Document.Title] by scanning content for the 1st <h1> tag.

func GenerateHTMLFile

func GenerateHTMLFile(t *template.Template, contentPathname, outputDirname string) error

GenerateHTMLFile executes template t with the document contentPathname, writing the minified result to a new file in outputDirname. (See GetHTMLPathname, GenerateDocument, and Minify.)

func GetHTMLPathname

func GetHTMLPathname(pathname, outputDirname string) (string, error)

GetHTMLPathname returns a pathname whose basename ends in .html and which resides in outputDirname, given an input pathname. If outputDirname is empty, returns a pathname that is a sibling of pathname. If the result is equal to pathname, returns an error.

func Minify

func Minify(w io.Writer, r io.Reader)

Minify minifies HTML, CSS, and JS in r and writes the result to w.

Types

type Document

type Document struct {
	Body  template.HTML
	Title string
}

Document represents a document with a raw HTML body, and a <title>. GenerateHTML will discover the Title.

TODO: discover all headings and generate a table of contents.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL