Documentation
¶
Overview ¶
Package documents offers files for download: minutes, reports, forms and policies. Each document has a date, a file from the media library or a link to an external address, and per language a title, a category and a Markdown description. Downloads are counted. Add an instance with:
app.Use(documents.Module("documents", "Documents"))
Upload files in the media library first and choose them in the document editor. When the module is mounted on a page it serves the list at "/" and the list of one category at "/category/{slug}"; the category slug is made from the category name. The website renders:
documents/list.gohtml ListView: documents newest first, also per year,
and the categories to filter on
Document.URL is the download address /_/<key>/<id>/download. It counts the download and redirects to the file or the external link, so it works on every page, also where the module is not mounted. Templates anywhere on the site can list documents without Go code:
{{range documents "documents" 5}}<a href="{{.URL}}">{{.Title}}</a> {{.FileType}} {{.SizeText}}{{end}}
{{range documentsIn "documents" "Minutes"}}{{.Date.Format "2 January 2006"}} {{.Title}}{{end}}
documentsIn matches the category name in the current language, ignoring case, or the category slug.
The site search finds published documents by title, description and category once the module is on a page. A result links to the document on the list (of its category), at #<ID>: give each document id="{{.ID}}".
Index ¶
- func Module(key, title string) webthings.Module
- type APICategory
- type APIDocument
- type APIFile
- type Category
- type Document
- type Fields
- type Item
- type ListView
- type Service
- func (s *Service) Download(ctx context.Context, id string) (string, error)
- func (s *Service) InCategory(ctx context.Context, locale, category string) ([]Document, error)
- func (s *Service) Latest(ctx context.Context, locale string, limit int) ([]Document, error)
- func (s *Service) Store() content.Store[Fields, Text]
- type Text
- type Year
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APICategory ¶
type APICategory struct {
Slug string `json:"slug"`
Name string `json:"name"`
// DocumentCount is the number of published documents in the category.
DocumentCount int `json:"document_count"`
// URL is the category's list on the site, null while the instance is
// on no page; DocumentsURL its documents in the API.
URL *string `json:"url"`
DocumentsURL string `json:"documents_url"`
}
APICategory is a category of published documents in one language, at /api/v1/<key>/categories and with each of its documents. Categories are the documents' category names; the slug is made from the name.
type APIDocument ¶
type APIDocument struct {
ID string `json:"id"`
Title string `json:"title"`
DescriptionHTML string `json:"description_html"`
// Category is null for a document without a category.
Category *APICategory `json:"category"`
// Date is the document's own date, such as that of a meeting, at
// midnight UTC.
Date time.Time `json:"date"`
// DownloadURL is the site's download address of the document, which
// counts the download and leads to the file or the external link, as
// on the site. External is set for a link, which has no File.
DownloadURL string `json:"download_url"`
External bool `json:"external"`
File *APIFile `json:"file"`
// URL is the document on the list of its category, or on the whole
// list (#<id>), null while the instance is on no page; APIURL the
// document in the API.
URL *string `json:"url"`
APIURL string `json:"api_url"`
UpdatedAt time.Time `json:"updated_at"`
}
APIDocument is a published document in the content API (see package api), at /api/v1/<key>/documents/{id} and in the list of /api/v1/<key>/documents. Documents have no page of their own: the list shows them whole, so the list has their description too.
type APIFile ¶
type APIFile struct {
Filename string `json:"filename"`
MIMEType string `json:"mime_type"`
// FileType is the file's extension in capitals, such as "PDF"; Size is
// in bytes.
FileType string `json:"file_type"`
Size int64 `json:"size"`
}
APIFile is the file of a document from the media library.
type Document ¶
type Document struct {
ID string
Title string
Description template.HTML
Category string
// CategoryURL lists the document's category, empty without a category or
// when the module is not mounted.
CategoryURL string
// Date is a calendar date (see frontend.Civil): {{date .Date}} shows the
// same day in every site timezone.
Date time.Time
// URL counts a download and redirects to the file or the link.
URL string
// External is true for a link instead of a file; the file details below
// are then empty.
External bool
Filename string
MIMEType string
// FileType is the file's extension in capitals, for example "PDF".
FileType string
Size int64
// SizeText is Size for people, for example "1.2 MB".
SizeText string
Downloads int
}
Document is a published document as templates see it.
type Fields ¶
type Fields struct {
File string `db:"file_id,null"`
Link string `db:"link"`
Date time.Time `db:"document_date"`
}
Fields are the language-independent parts of a document. A document has either a File or a Link. Date is the document's own date, for example the date of a meeting, stored as midnight UTC of that day.
type ListView ¶
type ListView struct {
// Title is the title of the page the module is mounted on, or the
// category name when the list is filtered.
Title string
// Documents are newest first, filtered by Category when it is set.
Documents []Document
// Years hold the same documents per year, newest first.
Years []Year
// Categories are all categories with documents, in alphabetical order.
Categories []Category
// Category is the active filter, or nil.
Category *Category
// AllURL lists all documents.
AllURL string
}
ListView is the data of documents/list.gohtml.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is one Documents instance, for the website's own code.
func (*Service) Download ¶
Download counts a download of a published document and returns where it is: the file's URL or the external link. It returns content.ErrNotFound for unknown and unpublished documents.
func (*Service) InCategory ¶
InCategory returns the published documents in locale whose category name is category, ignoring case, or whose category slug is category.