philote

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: MIT Imports: 15 Imported by: 1

README

philote

Minimalist library to serve markdown content as webpages.

License GitHub Actions Go Report Card Documentation

Index

Disclaimer

This library is under active development and subject to breaking changes at any time.

Install

go get github.com/fuzzingbits/philote

Getting Started

The following steps are how the Getting Started Example was created.

  1. Serve a philote.Site
// Create your instance of the philote.Site
site := &philote.Site{
    Content:  os.DirFS("./content"),
    Template: template.Must(template.ParseFiles("./template.go.html")),
}

// Prime the site
if err := site.Prime(); err != nil {
    panic(err)
}

// Serve the site
http.ListenAndServe(":8090", site)
  1. Create the Go HTML Template (./template.go.html):
<!doctype html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>Philote Site</title>
	</head>
	<body>
		<h1>Title: {{.Taxonomy.FrontMatter.Title}}</h1>
		<p>Description: {{.Taxonomy.FrontMatter.Description}}</p>
		{{.Taxonomy.Render}}
	</body>
</html>
  1. Create your first page (.content/index.md):
---
title: My First Page
date: 2021-01-01T00:00:00Z
description: "This is my first page"
---

This is being served with [philote](https://github.com/fuzzingbits/philote).

Templates

Taxonomy

The Site Taxonomy is automatically derived from the contents of the Content FileSystem:

  • all files are used as pages with their path and base filename used as the URL
    • Example: ./posts/hello-world.md == http://localhost:8000/posts/hello-world
  • all files must be have the .md extension
  • every directory (including the root directory) must include a index.md file.

Example:

┌── index.md
├── about.md
└── posts
    ├── index.md
    └── hello-world.md

FrontMatter

Every Markdown file must include FrontMatter at the beginning of the file. The FrontMatter should be in YAML format with fields matching the FrontMatter struct.

Example:

---
title: My First Page
date: 2021-01-01T00:00:00Z
description: "This is my first page"
---

This is being served with [philote](https://github.com/fuzzingbits/philote).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingIndex = errors.New("missing index")

ErrMissingIndex is when a index.md file is missing

Functions

This section is empty.

Types

type FrontMatter

type FrontMatter struct {
	Title       string
	Date        time.Time
	Description string
}

FrontMatter is a page

type Site

type Site struct {
	Content  fs.FS
	Template *template.Template
	Taxonomy *Taxonomy
	// contains filtered or unexported fields
}

Site is a philote site

func (*Site) Prime

func (site *Site) Prime() error

Prime the site

func (*Site) ServeHTTP

func (site *Site) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP the site based on the path provided

type Taxonomy

type Taxonomy struct {
	FrontMatter *FrontMatter
	Markdown    string
	Path        string
	Children    []*Taxonomy
	Parent      *Taxonomy `json:"-"`
}

Taxonomy is the overall structure of the page

func (*Taxonomy) Render

func (taxonomy *Taxonomy) Render() template.HTML

Render the markdown into HTML

type TemplatePayload

type TemplatePayload struct {
	Site     *Site
	Taxonomy *Taxonomy
}

TemplatePayload is what is sent into the template

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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