func (s *Site) renderAndWriteXML(name string, dest string, d interface{}, layouts ...string) error { renderBuffer := bp.GetBuffer() defer bp.PutBuffer(renderBuffer) renderBuffer.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n") err := s.render(name, d, renderBuffer, layouts...) outBuffer := bp.GetBuffer() defer bp.PutBuffer(outBuffer) var path []byte if viper.GetBool("RelativeURLs") { path = []byte(helpers.GetDottedRelativePath(dest)) } else { s := viper.GetString("BaseURL") if !strings.HasSuffix(s, "/") { s += "/" } path = []byte(s) } transformer := transform.NewChain(transform.AbsURLInXML) transformer.Apply(outBuffer, renderBuffer, path) if err == nil { err = s.WriteDestFile(dest, outBuffer) } return err }
func (s *Site) renderAndWritePage(name string, dest string, d interface{}, layouts ...string) error { renderBuffer := bp.GetBuffer() defer bp.PutBuffer(renderBuffer) err := s.render(name, d, renderBuffer, layouts...) outBuffer := bp.GetBuffer() defer bp.PutBuffer(outBuffer) transformLinks := transform.NewEmptyTransforms() if viper.GetBool("RelativeURLs") || viper.GetBool("CanonifyURLs") { transformLinks = append(transformLinks, transform.AbsURL) } if viper.GetBool("watch") && !viper.GetBool("DisableLiveReload") { transformLinks = append(transformLinks, transform.LiveReloadInject) } var path []byte if viper.GetBool("RelativeURLs") { translated, err := s.PageTarget().(target.OptionalTranslator).TranslateRelative(dest) if err != nil { return err } path = []byte(helpers.GetDottedRelativePath(translated)) } else if viper.GetBool("CanonifyURLs") { s := viper.GetString("BaseURL") if !strings.HasSuffix(s, "/") { s += "/" } path = []byte(s) } transformer := transform.NewChain(transformLinks...) transformer.Apply(outBuffer, renderBuffer, path) if err == nil { if err = s.WriteDestPage(dest, outBuffer); err != nil { return err } } return err }
func TestRelativeURL(t *testing.T) { tr := NewChain(AbsURL) applyWithPath(t.Errorf, tr, relurl_tests, helpers.GetDottedRelativePath(filepath.FromSlash("/post/sub/"))) }