bookshelf

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 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
    recent_limit: 5                # optional; books exposed via SiteData (default 5)

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}}

Recently-read widget (any template, e.g. homepage sidebar)

In addition to the bookshelf VirtualPage, the plugin exposes the newest books per locale on every page via Site.SiteData (see SiteDataProvider):

{{$bs := index .SiteData "bookshelf"}}
{{if $bs}}{{$recent := index (index $bs "recent") .CurrentLocale}}
  {{range $recent}}
    <a href="{{.LinkURL}}" rel="sponsored noopener noreferrer">
      <img src="{{.ImageURL}}" alt="{{.Title}}">
    </a>
  {{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) SiteData added in v1.5.0

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

SiteData implements plugin.SiteDataProvider. It exposes the most recently read books per locale on every rendered page, so themes can show a "recently read" widget outside the bookshelf page (e.g. the homepage sidebar).

The returned value has the shape:

{ "recent": { "<locale>": []BookEntry } }

Each locale's slice is sorted newest-first and capped at `recent_limit` books (config key under plugins.bookshelf; default defaultRecentLimit). Returns nil when no article declares books.

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