blog

package module
v0.0.0-...-d28c92d Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

README

Blog Module

A blog module for the platform that provides article management, search, and templating functionality.

Features

  • Markdown-based articles with YAML front matter
  • Full-text search with SQLite FTS5
  • Template rendering with vuego
  • Syntax highlighting for code blocks with Chroma
  • HTML and JSON APIs with content negotiation
  • Cache control for optimal performance

Quick Start

Configuration

Set the database connection:

export PLATFORM_DB_BLOG="sqlite:///tmp/blog.db"  # or sqlite://:memory: for development
Create Articles

Add markdown files to data/ directory:

---
title: My Article
description: A brief description
date: 2024-01-15
layout: post
ogImage: /path/to/image.png
---

# Article Content

Your markdown content here...
Run
task          # Start the service
task test     # Run tests
task cover    # Generate coverage report

API Endpoints

Method Path Response
GET /api/blog/articles JSON array of articles
GET /api/blog/articles/{slug} Single article JSON
GET /api/blog/search?q=query Search results
GET /blog/ Article list (HTML)
GET /blog/{slug} Article detail (HTML)

Architecture

The module consists of:

  • Module (blog.go) - Lifecycle management and route registration
  • Handlers (handlers.go) - HTTP request handling
  • Storage (storage/) - Database operations
  • Models (model/) - Data types
  • Templates (template/, theme/) - HTML rendering

Documentation

Testing

task test                 # Run all tests
task test:unit           # Unit tests only
task test:integration    # Integration tests only
task cover               # Generate coverage report
task bench               # Run benchmarks

Dependencies

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator generates static HTML files from blog content

func NewGenerator

func NewGenerator(m *Module, outputDir string) *Generator

NewGenerator creates a new Generator instance

func (*Generator) Generate

func (g *Generator) Generate(ctx context.Context) error

Generate generates all static HTML files

type Handlers

type Handlers struct {
	// contains filtered or unexported fields
}

Handlers handles HTTP requests for the blog module

func NewHandlers

func NewHandlers(repo *storage.Storage, themeFS fs.FS) (*Handlers, error)

NewHandlers creates a new Handlers instance with the given storage

func (*Handlers) GetArticleHTML

func (h *Handlers) GetArticleHTML(w http.ResponseWriter, r *http.Request)

GetArticleHTML returns a single article as HTML

func (*Handlers) GetArticleJSON

func (h *Handlers) GetArticleJSON(w http.ResponseWriter, r *http.Request)

GetArticleJSON returns a single article as JSON

func (*Handlers) GetAtomFeed

func (h *Handlers) GetAtomFeed(w http.ResponseWriter, r *http.Request)

GetAtomFeed returns an Atom XML feed of all articles

func (*Handlers) IndexHTML

func (h *Handlers) IndexHTML(w http.ResponseWriter, r *http.Request)

IndexHTML returns an HTML index page listing blogs

func (*Handlers) ListArticlesHTML

func (h *Handlers) ListArticlesHTML(w http.ResponseWriter, r *http.Request)

ListArticlesHTML returns an HTML list of articles

func (*Handlers) ListArticlesJSON

func (h *Handlers) ListArticlesJSON(w http.ResponseWriter, r *http.Request)

ListArticlesJSON returns a JSON list of all articles

func (*Handlers) SearchArticlesJSON

func (h *Handlers) SearchArticlesJSON(w http.ResponseWriter, r *http.Request)

SearchArticlesJSON performs full-text search on articles

type Module

type Module struct {
	platform.UnimplementedModule
	// contains filtered or unexported fields
}

Module implements the blog module for the platform

func NewModule

func NewModule(dataDir string) *Module

NewModule creates a new blog module instance

func (*Module) Mount

func (m *Module) Mount(_ context.Context, r platform.Router) error

Mount registers the blog routes with the router

func (*Module) Name

func (m *Module) Name() string

Name returns the module name

func (*Module) ScanMarkdownFiles

func (m *Module) ScanMarkdownFiles(ctx context.Context) (int, error)

ScanMarkdownFiles scans the data directory for markdown files and indexes them Returns the count of scanned files

func (*Module) SetRepository

func (m *Module) SetRepository(repo *storage.Storage)

SetRepository sets the repository on the module

func (*Module) Start

func (m *Module) Start(ctx context.Context) error

Start initializes the blog module by scanning markdown files and building the index

func (*Module) Stop

func (m *Module) Stop(context.Context) error

Stop is called when the module is shutting down

type OverlayFS

type OverlayFS struct {
	Upper fs.FS
	Lower fs.FS
}

func NewOverlayFS

func NewOverlayFS(upper, lower fs.FS) *OverlayFS

func (*OverlayFS) Glob

func (o *OverlayFS) Glob(pattern string) ([]string, error)

func (*OverlayFS) Open

func (o *OverlayFS) Open(name string) (fs.File, error)

func (*OverlayFS) ReadDir

func (o *OverlayFS) ReadDir(name string) ([]fs.DirEntry, error)

Directories

Path Synopsis
cmd
blog command
generate command

Jump to

Keyboard shortcuts

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