slugger struct

Fields:

  • seen (map[string]int)

Methods:

slug


Parameters:
  • text string

Returns:
  • string

Show/Hide Method Body
{
	slug := strings.ToLower(text)
	slug = slugRe.ReplaceAllString(slug, "")
	slug = strings.TrimSpace(slug)
	slug = strings.ReplaceAll(slug, " ", "-")
	if n, ok := s.seen[slug]; ok {
		s.seen[slug] = n + 1
		return fmt.Sprintf("%s-%d", slug, n)
	}
	s.seen[slug] = 1
	return slug
}

newSlugger function

Returns:

  • *slugger
Show/Hide Function Body
{ return &slugger{seen: make(map[string]int)} }

Plugin struct

Fields:

  • Sidebar (string)
  • loader (js.Func)
  • disableSEO (bool)

Methods:

Name


Returns:
  • string

Show/Hide Method Body
{ return "docs" }

Optional


Returns:
  • []core.Plugin

Show/Hide Method Body
{
	if p.disableSEO {
		return nil
	}
	return []core.Plugin{seo.New()}
}

Install


Parameters:
  • a *core.App

Show/Hide Method Body
{
	doc := js.Document()

	js.Fetch(p.Sidebar).Call("then", js.FuncOf(func(this js.Value, args []js.Value) any {
		res := args[0]
		res.Call("text").Call("then", js.FuncOf(func(this js.Value, args []js.Value) any {
			js.Set("__rfwDocsSidebar", args[0].String())
			doc.Call("dispatchEvent", js.CustomEvent().New("rfwSidebar"))
			return nil
		}))
		return nil
	}))

	p.loader = js.FuncOf(func(this js.Value, args []js.Value) any {
		if len(args) < 1 {
			return nil
		}
		path := args[0].String()
		js.Fetch(path).Call("then", js.FuncOf(func(this js.Value, args []js.Value) any {
			res := args[0]
			res.Call("text").Call("then", js.FuncOf(func(this js.Value, args []js.Value) any {
				content := args[0].String()
				mhs := markdown.Headings(content)
				headings := make([]any, len(mhs))
				for i, h := range mhs {
					headings[i] = map[string]any{"text": h.Text, "depth": h.Depth, "id": h.ID}
				}
				doc.Call("dispatchEvent", js.CustomEvent().New("rfwDoc", map[string]any{"detail": map[string]any{"path": path, "content": content, "headings": headings}}))
				return nil
			}))
			return nil
		}))
		return nil
	})
	js.Set("rfwLoadDoc", p.loader)
}

Build


Parameters:
  • json.RawMessage

Returns:
  • error

Show/Hide Method Body
{ return nil }

New function

Parameters:

  • sidebar string
  • disableSEO ...bool

Returns:

  • *Plugin
Show/Hide Function Body
{
	sidebar = fmt.Sprintf("%s?%s", sidebar, time.Now().Unix())
	p := &Plugin{Sidebar: sidebar}
	if len(disableSEO) > 0 {
		p.disableSEO = disableSEO[0]
	}
	return p
}

TestSlugger function

TestSlugger ensures slug generation is deterministic and handles duplicates.

Parameters:

  • t *testing.T
Show/Hide Function Body
{
	s := newSlugger()
	first := s.slug("Hello World!")
	if first != "hello-world" {
		t.Fatalf("expected 'hello-world', got %q", first)
	}
	second := s.slug("Hello World!")
	if second != "hello-world-1" {
		t.Fatalf("expected 'hello-world-1', got %q", second)
	}
}

LoadArticle function

LoadArticle fetches and renders the markdown document at the given path.

It relies on the rfwLoadDoc loader injected by the docs plugin and should

be used instead of direct js.Call invocations.

Parameters:

  • path string
Show/Hide Function Body
{
	js.Call("rfwLoadDoc", path)
}

LoadArticle function

LoadArticle is a no-op when not running in a js/wasm environment.

Parameters:

  • path string
Show/Hide Function Body
{}

fmt import

Import example:

import "fmt"

regexp import

Import example:

import "regexp"

strings import

Import example:

import "strings"

encoding/json import

Import example:

import "encoding/json"

fmt import

Import example:

import "fmt"

time import

Import example:

import "time"

github.com/rfwlab/rfw/v1/core import

Import example:

import "github.com/rfwlab/rfw/v1/core"

github.com/rfwlab/rfw/v1/js import

Import example:

import "github.com/rfwlab/rfw/v1/js"

Imported as:

js

github.com/rfwlab/rfw/v1/markdown import

Import example:

import "github.com/rfwlab/rfw/v1/markdown"

github.com/rfwlab/rfw/v1/plugins/seo import

Import example:

import "github.com/rfwlab/rfw/v1/plugins/seo"

testing import

Import example:

import "testing"

github.com/rfwlab/rfw/v1/js import

Import example:

import "github.com/rfwlab/rfw/v1/js"

Imported as:

js