changelog

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 7 Imported by: 0

README

go-changelog

go-changelog renders release sections from a CHANGELOG.md and provides a ready-to-use Bootstrap 5 display with a version link, new-release badge, modal, and localStorage reminder.

Installation

go get github.com/realholgi/go-changelog

Usage

package main

import (
	_ "embed"

	"github.com/realholgi/go-changelog"
)

//go:embed CHANGELOG.md
var changelogMarkdown string

// version is overridden for release builds with:
// go build -ldflags "-X main.version=v1.2.0" .
var version = "dev"

func main() {
	content := changelog.Prepare(changelogMarkdown, version)
	// Pass Content to html/template as part of the template data.
	_ = content
}

version belongs to the embedding application. Keep a development fallback and inject the release version during the build:

go build -ldflags "-X main.version=v1.2.0" .

The value should match the release heading in CHANGELOG.md. It is used to select the current release and derive the default modal ID and browser storage key. A value of dev disables the new-release badge reminder behavior.

Place the trigger and modal where the application needs them:

<nav>
  {{.Changelog.Trigger}}
</nav>

<script src="/static/bootstrap.bundle.min.js"></script>
{{.Changelog.Modal}}

The embedding application must load Bootstrap 5.

Customize the display with options:

content := changelog.PrepareWithOptions(markdown, version, changelog.Options{
	ModalID:    "releaseNotes",
	StorageKey: "my_app_changelog_seen",
	Title:      "Release notes",
	NewIn:      "New in",
	Close:      "Close",
	Confirm:    "Got it",
})

When ModalID and StorageKey are empty, go-changelog derives distinct, CSS-safe defaults from the current version. Set them explicitly when several displays represent the same version on one page.

Release headings must use this format:

## [Unreleased]

## [1.2.0] - 2026-07-24

Content.HTML contains every non-empty release section. Content.Date contains the date of the current version when that version exists in the changelog.

License

MIT

Documentation

Overview

Package changelog prepares a Keep a Changelog-style Markdown document for a reusable Bootstrap display.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Content added in v0.2.0

type Content struct {
	HTML string
	Date string
	// contains filtered or unexported fields
}

Content contains the rendered changelog and the current release date.

func Prepare added in v0.2.0

func Prepare(markdown, currentVersion string) Content

Prepare renders every non-empty release section with the default options.

func PrepareWithOptions added in v0.2.0

func PrepareWithOptions(markdown, currentVersion string, options Options) Content

PrepareWithOptions renders every non-empty release section in source order and configures the display.

func (Content) Modal added in v0.2.0

func (c Content) Modal() template.HTML

Modal renders the styles, Bootstrap modal, and localStorage behavior. The embedding application must load Bootstrap 5.

func (Content) Trigger added in v0.2.0

func (c Content) Trigger() template.HTML

Trigger renders the version display and, when changelog content is available, the trigger and badge for the Bootstrap modal.

type Options added in v0.2.0

type Options struct {
	ModalID    string
	StorageKey string
	Title      string
	NewIn      string
	Close      string
	Confirm    string
}

Options customizes display IDs, browser storage, and labels. Empty IDs and storage keys are derived from the current version; empty labels are replaced by English defaults.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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