Fix and refactor typos

This commit is contained in:
Cathrine Paulsen 2022-03-10 14:10:21 +01:00 committed by Bjørn Erik Pedersen
parent 31fbc081c9
commit 61cf3c9f63
3 changed files with 15 additions and 15 deletions

View file

@ -283,10 +283,10 @@ func (b *contentBuilder) applyArcheType(contentFilename, archetypeFilename strin
defer f.Close() defer f.Close()
if archetypeFilename == "" { if archetypeFilename == "" {
return b.cf.AppplyArchetypeTemplate(f, p, b.kind, DefaultArchetypeTemplateTemplate) return b.cf.ApplyArchetypeTemplate(f, p, b.kind, DefaultArchetypeTemplateTemplate)
} }
return b.cf.AppplyArchetypeFilename(f, p, b.kind, archetypeFilename) return b.cf.ApplyArchetypeFilename(f, p, b.kind, archetypeFilename)
} }

View file

@ -35,12 +35,12 @@ type ContentFactory struct {
// We parse the archetype templates as Go templates, so we need // We parse the archetype templates as Go templates, so we need
// to replace any shortcode with a temporary placeholder. // to replace any shortcode with a temporary placeholder.
shortocdeReplacerPre *strings.Replacer shortcodeReplacerPre *strings.Replacer
shortocdeReplacerPost *strings.Replacer shortcodeReplacerPost *strings.Replacer
} }
// AppplyArchetypeFilename archetypeFilename to w as a template using the given Page p as the foundation for the data context. // ApplyArchetypeFilename archetypeFilename to w as a template using the given Page p as the foundation for the data context.
func (f ContentFactory) AppplyArchetypeFilename(w io.Writer, p page.Page, archetypeKind, archetypeFilename string) error { func (f ContentFactory) ApplyArchetypeFilename(w io.Writer, p page.Page, archetypeKind, archetypeFilename string) error {
fi, err := f.h.SourceFilesystems.Archetypes.Fs.Stat(archetypeFilename) fi, err := f.h.SourceFilesystems.Archetypes.Fs.Stat(archetypeFilename)
if err != nil { if err != nil {
@ -57,12 +57,12 @@ func (f ContentFactory) AppplyArchetypeFilename(w io.Writer, p page.Page, archet
} }
return f.AppplyArchetypeTemplate(w, p, archetypeKind, string(templateSource)) return f.ApplyArchetypeTemplate(w, p, archetypeKind, string(templateSource))
} }
// AppplyArchetypeFilename templateSource to w as a template using the given Page p as the foundation for the data context. // ApplyArchetypeTemplate templateSource to w as a template using the given Page p as the foundation for the data context.
func (f ContentFactory) AppplyArchetypeTemplate(w io.Writer, p page.Page, archetypeKind, templateSource string) error { func (f ContentFactory) ApplyArchetypeTemplate(w io.Writer, p page.Page, archetypeKind, templateSource string) error {
ps := p.(*pageState) ps := p.(*pageState)
if archetypeKind == "" { if archetypeKind == "" {
archetypeKind = p.Type() archetypeKind = p.Type()
@ -75,7 +75,7 @@ func (f ContentFactory) AppplyArchetypeTemplate(w io.Writer, p page.Page, archet
File: p.File(), File: p.File(),
} }
templateSource = f.shortocdeReplacerPre.Replace(templateSource) templateSource = f.shortcodeReplacerPre.Replace(templateSource)
templ, err := ps.s.TextTmpl().Parse("archetype.md", string(templateSource)) templ, err := ps.s.TextTmpl().Parse("archetype.md", string(templateSource))
if err != nil { if err != nil {
@ -87,7 +87,7 @@ func (f ContentFactory) AppplyArchetypeTemplate(w io.Writer, p page.Page, archet
return errors.Wrapf(err, "failed to execute archetype template: %s", err) return errors.Wrapf(err, "failed to execute archetype template: %s", err)
} }
_, err = io.WriteString(w, f.shortocdeReplacerPost.Replace(result)) _, err = io.WriteString(w, f.shortcodeReplacerPost.Replace(result))
return err return err
@ -116,7 +116,7 @@ func (f ContentFactory) CreateContentPlaceHolder(filename string) (string, error
return "", err return "", err
} }
// This will be overwritten later, just write a placholder to get // This will be overwritten later, just write a placeholder to get
// the paths correct. // the paths correct.
placeholder := `--- placeholder := `---
title: "Content Placeholder" title: "Content Placeholder"
@ -135,12 +135,12 @@ _build:
func NewContentFactory(h *HugoSites) ContentFactory { func NewContentFactory(h *HugoSites) ContentFactory {
return ContentFactory{ return ContentFactory{
h: h, h: h,
shortocdeReplacerPre: strings.NewReplacer( shortcodeReplacerPre: strings.NewReplacer(
"{{<", "{x{<", "{{<", "{x{<",
"{{%", "{x{%", "{{%", "{x{%",
">}}", ">}x}", ">}}", ">}x}",
"%}}", "%}x}"), "%}}", "%}x}"),
shortocdeReplacerPost: strings.NewReplacer( shortcodeReplacerPost: strings.NewReplacer(
"{x{<", "{{<", "{x{<", "{{<",
"{x{%", "{{%", "{x{%", "{{%",
">}x}", ">}}", ">}x}", ">}}",

View file

@ -52,7 +52,7 @@ Hello World.
b.Assert(p, qt.Not(qt.IsNil)) b.Assert(p, qt.Not(qt.IsNil))
var buf bytes.Buffer var buf bytes.Buffer
b.Assert(cf.AppplyArchetypeFilename(&buf, p, "", "post.md"), qt.IsNil) b.Assert(cf.ApplyArchetypeFilename(&buf, p, "", "post.md"), qt.IsNil)
b.Assert(buf.String(), qt.Contains, `title: "Mypage"`) b.Assert(buf.String(), qt.Contains, `title: "Mypage"`)
}) })