mirror of
https://github.com/veggiemonk/awesome-docker.git
synced 2026-03-11 17:48:58 -05:00
Pages deploy ux a11y refresh (#1252)
* Improve Pages workflow and redesign site with accessible sidebar navigation * README clean up * Use Makefile website target in Pages deploy workflow
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/yuin/goldmark"
|
||||
"github.com/yuin/goldmark/extension"
|
||||
"github.com/yuin/goldmark/parser"
|
||||
"github.com/yuin/goldmark/renderer/html"
|
||||
)
|
||||
|
||||
@@ -27,6 +28,7 @@ func Build(markdownPath, templatePath, outputPath string) error {
|
||||
// Convert markdown to HTML
|
||||
gm := goldmark.New(
|
||||
goldmark.WithExtensions(extension.GFM),
|
||||
goldmark.WithParserOptions(parser.WithAutoHeadingID()),
|
||||
goldmark.WithRendererOptions(html.WithUnsafe()),
|
||||
)
|
||||
var buf bytes.Buffer
|
||||
|
||||
@@ -131,3 +131,42 @@ func TestBuildFailsWithoutPlaceholder(t *testing.T) {
|
||||
t.Fatal("expected Build to fail when template has no supported placeholder")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildAddsHeadingIDs(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
|
||||
md := "# Getting Started\n\n## Next Step\n"
|
||||
mdPath := filepath.Join(dir, "README.md")
|
||||
if err := os.WriteFile(mdPath, []byte(md), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tmpl := `<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<section id="md" class="main-content"></section>
|
||||
</body>
|
||||
</html>`
|
||||
tmplPath := filepath.Join(dir, "template.html")
|
||||
if err := os.WriteFile(tmplPath, []byte(tmpl), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
outPath := filepath.Join(dir, "index.html")
|
||||
if err := Build(mdPath, tmplPath, outPath); err != nil {
|
||||
t.Fatalf("Build failed: %v", err)
|
||||
}
|
||||
|
||||
content, err := os.ReadFile(outPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
html := string(content)
|
||||
if !strings.Contains(html, `id="getting-started"`) {
|
||||
t.Error("expected auto-generated heading id for h1")
|
||||
}
|
||||
if !strings.Contains(html, `id="next-step"`) {
|
||||
t.Error("expected auto-generated heading id for h2")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user