23 lines
552 B
Go
23 lines
552 B
Go
package site
|
|
|
|
import "strings"
|
|
|
|
func (s Site) PublicURL(lang string, slug string) *string {
|
|
if s.PublicURLPattern == nil || lang == "" {
|
|
return nil
|
|
}
|
|
filled := strings.NewReplacer(LangPlaceholder, lang, SlugPlaceholder, slug).Replace(*s.PublicURLPattern)
|
|
return &filled
|
|
}
|
|
|
|
func (s Site) ArticleURL(lang string, slug string) (string, bool) {
|
|
if localized := s.PublicURL(lang, slug); localized != nil {
|
|
return *localized, true
|
|
}
|
|
return s.LegacyURL(slug), false
|
|
}
|
|
|
|
func (s Site) LegacyURL(slug string) string {
|
|
return s.BaseURL + "/" + slug
|
|
}
|