articles

package
v0.0.0-...-9431910 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package articles implements an app for displaying articles from files.

This application is intended to display a collection of articles where each article is represented by a file. The file must have one of the following extensions:

.html, .txt, .md

To load articles written in markdown (.md extension), your application must import gondola/template/markdown, like e.g.

 import (
	    _ "gondola/template/markdown"
 )

Each file is composed of first the article text and then a set of properties separated by one empty line. Each property takes the form:

[name] = value

Where value must a valid value for the property type. The currently parsed properties are:

  • title (required): Indicates the article title and can be used to generate the article URL when no slug is specified.
  • id (optional): The article id, used to reverse the article. If it's not present, the article filename without extension is used as its id.
  • slug (optional): The article slug. If present, it overrides the generated value from the title.
  • synopsis (optional): A small text about the article shown in article listings.
  • updated (optional): Indicates an update to the file.
  • priority (optional): When listing the articles, the ones with lower priority are shown first.

The title, slug and updated field might appear multiple times. It's recommended that if you change the title or the slug of an article, you do so by adding a new property BEFORE the previous one without deleting the old one. This allows the articles app to redirect users from the old URL to the new one.

This package also adds a template function named reverse_article. It can be used to find the URL of an article from its id. e.g.

{{ reverse_article "article-id" }}

The typical usage of this application is as follows:

articlesApp := articles.New()
if _, err := articlesApp.LoadDir(pathutil.Relative("articles")); err != nil {
    panic(err)
}

myapp.Include("/articles/", articlesApp.App, "articles-base.html")

Index

Constants

View Source
const (
	ArticleHandlerName     = "articles-article"
	ArticleListHandlerName = "articles-list"
)

Variables

This section is empty.

Functions

func ArticleHandler

func ArticleHandler(ctx *app.Context)

func ArticleListHandler

func ArticleListHandler(ctx *app.Context)

func List

func List(fs vfs.VFS, dir string) ([]*article.Article, error)

List returns the articles found in the given directory in the fs argument, recursively.

Types

type App

type App struct {
	reusableapp.App
}

func New

func New() *App

func (*App) Load

func (a *App) Load(fs vfs.VFS, dir string) ([]*article.Article, error)

Load loads articles from the given directory in the given fs into the given app.

func (*App) LoadDir

func (a *App) LoadDir(dir string) ([]*article.Article, error)

LoadDir works like Load, but loads the articles from the given directory in the local filesystem.

Directories

Path Synopsis
Package article includes common types and functions for the articles app and command.
Package article includes common types and functions for the articles app and command.
cmd
articles
The articles command is used for easily managing article files.
The articles command is used for easily managing article files.

Jump to

Keyboard shortcuts

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