Skip to content

Commit

Permalink
add baseURL + fix active link check
Browse files Browse the repository at this point in the history
  • Loading branch information
ihadeed committed Nov 11, 2019
1 parent e5b9da3 commit 69b5e20
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type ParserConfig struct {
SiteTitle string `yaml:"siteTitle"`
Description string `yaml:"description"`
Repo string `yaml:"repo"`
BaseURL string `yaml:"baseUrl"`
}

type File struct {
Expand Down Expand Up @@ -183,6 +184,8 @@ type RenderContext struct {
Content template.HTML
OutDir string
OutFile string
BaseURL string
Link string
}

func (p *Parser) Render() error {
Expand Down Expand Up @@ -223,6 +226,7 @@ func (p *Parser) Render() error {
Content: template.HTML(o),
OutDir: outDir,
OutFile: outFile,
Link: f.Path,
}

rndCtxs = append(rndCtxs, &ctx)
Expand Down Expand Up @@ -280,13 +284,14 @@ func (p *Parser) Render() error {
ctx.SiteTitle = p.Config.SiteTitle
ctx.Description = p.Config.Description
ctx.MenuItems = menuItems
ctx.BaseURL = p.Config.BaseURL

for _, mit := range menuItems {
if mit.Group {
for _, cmit := range mit.Items {
cmit.Active = cmit.Title == ctx.Title
cmit.Active = cmit.Link == ctx.Link
}
} else if mit.Title == ctx.Title {
} else if mit.Link == ctx.Link {
mit.Active = true
} else {
mit.Active = false
Expand Down
1 change: 1 addition & 0 deletions templates/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const BaseTemplate = `<!DOCTYPE html>
<meta charset="UTF-8">
<title>{{ .Title }}</title>
{{ if .Description }}<meta name="description" content="{{ .Description }}">{{ end }}
{{ if .BaseURL }}<base href="{{ .BaseURL }}" />{{ end }}
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#fafafa">
Expand Down

0 comments on commit 69b5e20

Please sign in to comment.