bookshelf

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package bookshelf is a gohan built-in SitePlugin that generates a bookshelf page by aggregating book entries from every article's front-matter.

Configuration (config.yaml)

plugins:
  bookshelf:
    enabled: true
    tag: "your-associate-tag-22"   # Amazon Associates tracking tag

Front-matter (article .md) — same key used by amazon_books plugin

books:
  - asin: "4781920004"           # Amazon ASIN — generates image + Amazon link
    title: "組織を変える5つの対話"   # optional; used for alt text
  - url: "https://booth.pm/..."  # non-Amazon: direct sales URL (no cover image)
    title: "同人誌タイトル"

Template usage (bookshelf.html)

{{range index .VirtualPageData "categories"}}
  <h2>{{if .Name}}{{.Name}}{{else}}Uncategorized{{end}}</h2>
  {{range .Books}}
    <a href="{{.LinkURL}}" target="_blank" rel="noopener">
      <img src="{{.ImageURL}}" alt="{{.Title}}">
    </a>
    {{if .ArticleURL}}<a href="{{.ArticleURL}}">{{.ArticleTitle}}</a>{{end}}
  {{end}}
{{end}}

Index

Constants

View Source
const (
	// Name is the plugin identifier used as the key in config.yaml and registry.
	Name = "bookshelf"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BookEntry

type BookEntry struct {
	ASIN         string
	Title        string
	ImageURL     string
	LinkURL      string
	ArticleSlug  string
	ArticleTitle string
	ArticleURL   string
	Date         time.Time
	Categories   []string
}

BookEntry is the data exposed to templates for a single book on the bookshelf.

type Bookshelf

type Bookshelf struct{}

Bookshelf implements SitePlugin.

func New

func New() *Bookshelf

New returns a new Bookshelf plugin instance.

func (*Bookshelf) Enabled

func (b *Bookshelf) Enabled(cfg map[string]interface{}) bool

Enabled returns true when the plugin config has enabled: true.

func (*Bookshelf) Name

func (b *Bookshelf) Name() string

Name returns the plugin identifier.

func (*Bookshelf) VirtualPages

func (b *Bookshelf) VirtualPages(site *model.Site, cfg map[string]interface{}) ([]*model.VirtualPage, error)

VirtualPages collects all book entries from article front-matter and returns one VirtualPage per locale containing the aggregated bookshelf data. Each page's Data map contains:

"books"      []BookEntry       — all entries sorted by date descending
"categories" []CategoryGroup   — entries grouped by article category, sorted alphabetically

type CategoryGroup added in v1.0.14

type CategoryGroup struct {
	Name  string
	Books []BookEntry
}

CategoryGroup groups BookEntries under a single category name. When Name is empty the books have no category assigned.

Jump to

Keyboard shortcuts

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