Skip to content

Commit

Permalink
Add hreflangs to manpages
Browse files Browse the repository at this point in the history
fixes #42
  • Loading branch information
stapelberg committed Jan 22, 2017
1 parent 735413a commit 24fc037
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions assets/header.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
{{ template "style" }}
</style>
<link rel="search" title="Debian manpages" type="application/opensearchdescription+xml" href="/opensearch.xml">
{{ if and (.HrefLangs) (gt (len .HrefLangs) 1) -}}
{{ range $idx, $man := .HrefLangs -}}
<link rel="alternate" href="/{{ $man.ServingPath }}.html" hreflang="{{ $man.LanguageTag }}">
{{ end -}}
{{ end -}}
</head>
<body>
<div id="header">
Expand Down
3 changes: 3 additions & 0 deletions cmd/debiman/renderaux.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func renderAux(destDir string, gv globalView) error {
FooterExtra string
Suites []string
Meta *manpage.Meta
HrefLangs []*manpage.Meta
}{
Title: "index",
Suites: suites,
Expand All @@ -74,6 +75,7 @@ func renderAux(destDir string, gv globalView) error {
Breadcrumbs breadcrumbs
FooterExtra string
Meta *manpage.Meta
HrefLangs []*manpage.Meta
}{
Title: "FAQ",
DebimanVersion: debimanVersion,
Expand All @@ -89,6 +91,7 @@ func renderAux(destDir string, gv globalView) error {
Breadcrumbs breadcrumbs
FooterExtra string
Meta *manpage.Meta
HrefLangs []*manpage.Meta
}{
Title: "FAQ",
DebimanVersion: debimanVersion,
Expand Down
1 change: 1 addition & 0 deletions cmd/debiman/rendercontents.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func renderContents(dest, suite string, bins []string) error {
Bins []string
Suite string
Meta *manpage.Meta
HrefLangs []*manpage.Meta
}{
Title: fmt.Sprintf("Contents of Debian %s", suite),
DebimanVersion: debimanVersion,
Expand Down
9 changes: 9 additions & 0 deletions cmd/debiman/rendermanpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ type manpagePrepData struct {
Sections []*manpage.Meta
Bins []*manpage.Meta
Langs []*manpage.Meta
HrefLangs []*manpage.Meta
Meta *manpage.Meta
TOC []string
Ambiguous map[*manpage.Meta]bool
Expand Down Expand Up @@ -410,12 +411,18 @@ func rendermanpageprep(converter *convert.Process, job renderJob) (*template.Tem
byLang[v.Language] = append(byLang[v.Language], v)
}
langs := make([]*manpage.Meta, 0, len(byLang))
hrefLangs := make([]*manpage.Meta, 0, len(byLang))
for _, all := range byLang {
for _, e := range all {
langs = append(langs, e)
if len(all) > 1 {
ambiguous[e] = true
}
// hreflang consists only of language and region,
// scripts are not supported.
if !strings.Contains(e.Language, "@") {
hrefLangs = append(hrefLangs, e)
}
}
}

Expand All @@ -426,6 +433,7 @@ func rendermanpageprep(converter *convert.Process, job renderJob) (*template.Tem
// TODO(stapelberg): is english collation always the same as
// strings.Sort (at least on the list of languages)?
collate.New(language.English).Sort(byLanguage(langs))
collate.New(language.English).Sort(byLanguage(hrefLangs))

t := manpageTmpl
title := fmt.Sprintf("%s(%s) — %s — Debian %s", meta.Name, meta.Section, meta.Package.Binarypkg, meta.Package.Suite)
Expand Down Expand Up @@ -464,6 +472,7 @@ func rendermanpageprep(converter *convert.Process, job renderJob) (*template.Tem
Sections: sections,
Bins: bins,
Langs: langs,
HrefLangs: hrefLangs,
Meta: meta,
TOC: toc,
Ambiguous: ambiguous,
Expand Down
1 change: 1 addition & 0 deletions cmd/debiman/renderpkgindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func renderPkgindex(dest string, manpageByName map[string]*manpage.Meta) error {
Meta *manpage.Meta
ManpageByName map[string]*manpage.Meta
Mans []string
HrefLangs []*manpage.Meta
}{
Title: fmt.Sprintf("Manpages of %s in Debian %s", first.Package.Binarypkg, first.Package.Suite),
DebimanVersion: debimanVersion,
Expand Down
1 change: 1 addition & 0 deletions internal/aux/aux.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (s *Server) HandleRedirect(w http.ResponseWriter, r *http.Request) {
Manpage string
BestChoice redirect.IndexEntry
Meta *manpage.Meta
HrefLangs []*manpage.Meta
}{
Title: "Not Found",
DebimanVersion: s.debimanVersion,
Expand Down
2 changes: 1 addition & 1 deletion internal/bundled/GENERATED_bundled.go

Large diffs are not rendered by default.

0 comments on commit 24fc037

Please sign in to comment.