本文整理汇总了Golang中github.com/spf13/hugo/hugofs.Destination函数的典型用法代码示例。如果您正苦于以下问题:Golang Destination函数的具体用法?Golang Destination怎么用?Golang Destination使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Destination函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestPageCount
func TestPageCount(t *testing.T) {
testCommonResetState()
hugofs.InitMemFs()
viper.Set("uglyURLs", false)
viper.Set("paginate", 10)
s := &Site{
Source: &source.InMemorySource{ByteSource: urlFakeSource},
Language: helpers.NewDefaultLanguage(),
}
if err := buildAndRenderSite(s, "indexes/blue.html", indexTemplate); err != nil {
t.Fatalf("Failed to build site: %s", err)
}
_, err := hugofs.Destination().Open("public/blue")
if err != nil {
t.Errorf("No indexed rendered.")
}
for _, s := range []string{
"public/sd1/foo/index.html",
"public/sd2/index.html",
"public/sd3/index.html",
"public/sd4.html",
} {
if _, err := hugofs.Destination().Open(filepath.FromSlash(s)); err != nil {
t.Errorf("No alias rendered: %s", s)
}
}
}
示例2: TestPageCount
func TestPageCount(t *testing.T) {
viper.Reset()
defer viper.Reset()
hugofs.InitMemFs()
viper.Set("uglyurls", false)
viper.Set("paginate", 10)
s := &Site{
Source: &source.InMemorySource{ByteSource: urlFakeSource},
}
s.initializeSiteInfo()
s.prepTemplates("indexes/blue.html", indexTemplate)
if err := s.createPages(); err != nil {
t.Errorf("Unable to create pages: %s", err)
}
if err := s.buildSiteMeta(); err != nil {
t.Errorf("Unable to build site metadata: %s", err)
}
if err := s.renderSectionLists(); err != nil {
t.Errorf("Unable to render section lists: %s", err)
}
if err := s.renderAliases(); err != nil {
t.Errorf("Unable to render site lists: %s", err)
}
_, err := hugofs.Destination().Open("blue")
if err != nil {
t.Errorf("No indexed rendered.")
}
//expected := ".."
//if string(blueIndex) != expected {
//t.Errorf("Index template does not match expected: %q, got: %q", expected, string(blueIndex))
//}
for _, s := range []string{
"sd1/foo/index.html",
"sd2/index.html",
"sd3/index.html",
"sd4.html",
} {
if _, err := hugofs.Destination().Open(filepath.FromSlash(s)); err != nil {
t.Errorf("No alias rendered: %s", s)
}
}
}
示例3: copyStatic
func copyStatic() error {
publishDir := helpers.AbsPathify(viper.GetString("publishDir")) + helpers.FilePathSeparator
// If root, remove the second '/'
if publishDir == "//" {
publishDir = helpers.FilePathSeparator
}
// Includes both theme/static & /static
staticSourceFs := getStaticSourceFs()
if staticSourceFs == nil {
jww.WARN.Println("No static directories found to sync")
return nil
}
syncer := fsync.NewSyncer()
syncer.NoTimes = viper.GetBool("notimes")
syncer.SrcFs = staticSourceFs
syncer.DestFs = hugofs.Destination()
// Now that we are using a unionFs for the static directories
// We can effectively clean the publishDir on initial sync
syncer.Delete = viper.GetBool("cleanDestinationDir")
if syncer.Delete {
jww.INFO.Println("removing all files from destination that don't exist in static dirs")
}
jww.INFO.Println("syncing static files to", publishDir)
// because we are using a baseFs (to get the union right).
// set sync src to root
return syncer.Sync(publishDir, helpers.FilePathSeparator)
}
示例4: destinationExists
func destinationExists(filename string) bool {
b, err := helpers.Exists(filename, hugofs.Destination())
if err != nil {
panic(err)
}
return b
}
示例5: serve
func serve(port int) {
if renderToDisk {
jww.FEEDBACK.Println("Serving pages from " + helpers.AbsPathify(viper.GetString("publishDir")))
} else {
jww.FEEDBACK.Println("Serving pages from memory")
}
httpFs := afero.NewHttpFs(hugofs.Destination())
fs := filesOnlyFs{httpFs.Dir(helpers.AbsPathify(viper.GetString("publishDir")))}
fileserver := http.FileServer(fs)
// We're only interested in the path
u, err := url.Parse(viper.GetString("baseURL"))
if err != nil {
jww.ERROR.Fatalf("Invalid baseURL: %s", err)
}
if u.Path == "" || u.Path == "/" {
http.Handle("/", fileserver)
} else {
http.Handle(u.Path, http.StripPrefix(u.Path, fileserver))
}
jww.FEEDBACK.Printf("Web Server is available at %s (bind address %s)\n", u.String(), serverInterface)
fmt.Println("Press Ctrl+C to stop")
endpoint := net.JoinHostPort(serverInterface, strconv.Itoa(port))
err = http.ListenAndServe(endpoint, nil)
if err != nil {
jww.ERROR.Printf("Error: %s\n", err.Error())
os.Exit(1)
}
}
示例6: Publish
func (h *HTMLRedirectAlias) Publish(path string, permalink string, page interface{}) (err error) {
if path, err = h.Translate(path); err != nil {
jww.ERROR.Printf("%s, skipping.", err)
return nil
}
t := "alias"
if strings.HasSuffix(path, ".xhtml") {
t = "alias-xhtml"
}
template := defaultAliasTemplates
if h.Templates != nil {
template = h.Templates
t = "alias.html"
}
buffer := new(bytes.Buffer)
err = template.ExecuteTemplate(buffer, t, &AliasNode{permalink, page})
if err != nil {
return
}
return helpers.WriteToDisk(path, buffer, hugofs.Destination())
}
示例7: TestDefaultHandler
func TestDefaultHandler(t *testing.T) {
testCommonResetState()
hugofs.InitMemFs()
sources := []source.ByteSource{
{Name: filepath.FromSlash("sect/doc1.html"), Content: []byte("---\nmarkup: markdown\n---\n# title\nsome *content*")},
{Name: filepath.FromSlash("sect/doc2.html"), Content: []byte("<!doctype html><html><body>more content</body></html>")},
{Name: filepath.FromSlash("sect/doc3.md"), Content: []byte("# doc3\n*some* content")},
{Name: filepath.FromSlash("sect/doc4.md"), Content: []byte("---\ntitle: doc4\n---\n# doc4\n*some content*")},
{Name: filepath.FromSlash("sect/doc3/img1.png"), Content: []byte("‰PNG ��� IHDR����������:~›U��� IDATWcø��ZMoñ����IEND®B`‚")},
{Name: filepath.FromSlash("sect/img2.gif"), Content: []byte("GIF89a��€��ÿÿÿ���,�������D�;")},
{Name: filepath.FromSlash("sect/img2.spf"), Content: []byte("****FAKE-FILETYPE****")},
{Name: filepath.FromSlash("doc7.html"), Content: []byte("<html><body>doc7 content</body></html>")},
{Name: filepath.FromSlash("sect/doc8.html"), Content: []byte("---\nmarkup: md\n---\n# title\nsome *content*")},
}
viper.Set("DefaultExtension", "html")
viper.Set("verbose", true)
s := &Site{
Source: &source.InMemorySource{ByteSource: sources},
targets: targetList{page: &target.PagePub{UglyURLs: true, PublishDir: "public"}},
Language: helpers.NewLanguage("en"),
}
if err := buildAndRenderSite(s,
"_default/single.html", "{{.Content}}",
"head", "<head><script src=\"script.js\"></script></head>",
"head_abs", "<head><script src=\"/script.js\"></script></head>"); err != nil {
t.Fatalf("Failed to render site: %s", err)
}
tests := []struct {
doc string
expected string
}{
{filepath.FromSlash("public/sect/doc1.html"), "\n\n<h1 id=\"title\">title</h1>\n\n<p>some <em>content</em></p>\n"},
{filepath.FromSlash("public/sect/doc2.html"), "<!doctype html><html><body>more content</body></html>"},
{filepath.FromSlash("public/sect/doc3.html"), "\n\n<h1 id=\"doc3\">doc3</h1>\n\n<p><em>some</em> content</p>\n"},
{filepath.FromSlash("public/sect/doc3/img1.png"), string([]byte("‰PNG ��� IHDR����������:~›U��� IDATWcø��ZMoñ����IEND®B`‚"))},
{filepath.FromSlash("public/sect/img2.gif"), string([]byte("GIF89a��€��ÿÿÿ���,�������D�;"))},
{filepath.FromSlash("public/sect/img2.spf"), string([]byte("****FAKE-FILETYPE****"))},
{filepath.FromSlash("public/doc7.html"), "<html><body>doc7 content</body></html>"},
{filepath.FromSlash("public/sect/doc8.html"), "\n\n<h1 id=\"title\">title</h1>\n\n<p>some <em>content</em></p>\n"},
}
for _, test := range tests {
file, err := hugofs.Destination().Open(test.doc)
if err != nil {
t.Fatalf("Did not find %s in target.", test.doc)
}
content := helpers.ReaderToString(file)
if content != test.expected {
t.Errorf("%s content expected:\n%q\ngot:\n%q", test.doc, test.expected, content)
}
}
}
示例8: TestRobotsTXTOutput
func TestRobotsTXTOutput(t *testing.T) {
testCommonResetState()
hugofs.InitMemFs()
viper.Set("baseurl", "http://auth/bub/")
viper.Set("enableRobotsTXT", true)
s := &Site{
Source: &source.InMemorySource{ByteSource: weightedSources},
Language: helpers.NewDefaultLanguage(),
}
if err := buildAndRenderSite(s, "robots.txt", robotTxtTemplate); err != nil {
t.Fatalf("Failed to build site: %s", err)
}
robotsFile, err := hugofs.Destination().Open("public/robots.txt")
if err != nil {
t.Fatalf("Unable to locate: robots.txt")
}
robots := helpers.ReaderToBytes(robotsFile)
if !bytes.HasPrefix(robots, []byte("User-agent: Googlebot")) {
t.Errorf("Robots file should start with 'User-agentL Googlebot'. %s", robots)
}
}
示例9: TestSkipRender
func TestSkipRender(t *testing.T) {
testCommonResetState()
hugofs.InitMemFs()
sources := []source.ByteSource{
{Name: filepath.FromSlash("sect/doc1.html"), Content: []byte("---\nmarkup: markdown\n---\n# title\nsome *content*")},
{Name: filepath.FromSlash("sect/doc2.html"), Content: []byte("<!doctype html><html><body>more content</body></html>")},
{Name: filepath.FromSlash("sect/doc3.md"), Content: []byte("# doc3\n*some* content")},
{Name: filepath.FromSlash("sect/doc4.md"), Content: []byte("---\ntitle: doc4\n---\n# doc4\n*some content*")},
{Name: filepath.FromSlash("sect/doc5.html"), Content: []byte("<!doctype html><html>{{ template \"head\" }}<body>body5</body></html>")},
{Name: filepath.FromSlash("sect/doc6.html"), Content: []byte("<!doctype html><html>{{ template \"head_abs\" }}<body>body5</body></html>")},
{Name: filepath.FromSlash("doc7.html"), Content: []byte("<html><body>doc7 content</body></html>")},
{Name: filepath.FromSlash("sect/doc8.html"), Content: []byte("---\nmarkup: md\n---\n# title\nsome *content*")},
}
viper.Set("defaultExtension", "html")
viper.Set("verbose", true)
viper.Set("canonifyURLs", true)
viper.Set("baseURL", "http://auth/bub")
s := &Site{
Source: &source.InMemorySource{ByteSource: sources},
targets: targetList{page: &target.PagePub{UglyURLs: true}},
Language: helpers.NewDefaultLanguage(),
}
if err := buildAndRenderSite(s,
"_default/single.html", "{{.Content}}",
"head", "<head><script src=\"script.js\"></script></head>",
"head_abs", "<head><script src=\"/script.js\"></script></head>"); err != nil {
t.Fatalf("Failed to build site: %s", err)
}
tests := []struct {
doc string
expected string
}{
{filepath.FromSlash("sect/doc1.html"), "\n\n<h1 id=\"title\">title</h1>\n\n<p>some <em>content</em></p>\n"},
{filepath.FromSlash("sect/doc2.html"), "<!doctype html><html><body>more content</body></html>"},
{filepath.FromSlash("sect/doc3.html"), "\n\n<h1 id=\"doc3\">doc3</h1>\n\n<p><em>some</em> content</p>\n"},
{filepath.FromSlash("sect/doc4.html"), "\n\n<h1 id=\"doc4\">doc4</h1>\n\n<p><em>some content</em></p>\n"},
{filepath.FromSlash("sect/doc5.html"), "<!doctype html><html><head><script src=\"script.js\"></script></head><body>body5</body></html>"},
{filepath.FromSlash("sect/doc6.html"), "<!doctype html><html><head><script src=\"http://auth/bub/script.js\"></script></head><body>body5</body></html>"},
{filepath.FromSlash("doc7.html"), "<html><body>doc7 content</body></html>"},
{filepath.FromSlash("sect/doc8.html"), "\n\n<h1 id=\"title\">title</h1>\n\n<p>some <em>content</em></p>\n"},
}
for _, test := range tests {
file, err := hugofs.Destination().Open(test.doc)
if err != nil {
t.Fatalf("Did not find %s in target.", test.doc)
}
content := helpers.ReaderToString(file)
if content != test.expected {
t.Errorf("%s content expected:\n%q\ngot:\n%q", test.doc, test.expected, content)
}
}
}
示例10: Publish
func (fs *Filesystem) Publish(path string, r io.Reader) (err error) {
translated, err := fs.Translate(path)
if err != nil {
return
}
return helpers.WriteToDisk(translated, r, hugofs.Destination())
}
示例11: TestAbsURLify
func TestAbsURLify(t *testing.T) {
testCommonResetState()
viper.Set("defaultExtension", "html")
hugofs.InitMemFs()
sources := []source.ByteSource{
{Name: filepath.FromSlash("sect/doc1.html"), Content: []byte("<!doctype html><html><head></head><body><a href=\"#frag1\">link</a></body></html>")},
{Name: filepath.FromSlash("blue/doc2.html"), Content: []byte("---\nf: t\n---\n<!doctype html><html><body>more content</body></html>")},
}
for _, baseURL := range []string{"http://auth/bub", "http://base", "//base"} {
for _, canonify := range []bool{true, false} {
viper.Set("canonifyURLs", canonify)
viper.Set("baseURL", baseURL)
s := &Site{
Source: &source.InMemorySource{ByteSource: sources},
targets: targetList{page: &target.PagePub{UglyURLs: true}},
Language: helpers.NewDefaultLanguage(),
}
t.Logf("Rendering with baseURL %q and canonifyURLs set %v", viper.GetString("baseURL"), canonify)
if err := buildAndRenderSite(s, "blue/single.html", templateWithURLAbs); err != nil {
t.Fatalf("Failed to build site: %s", err)
}
tests := []struct {
file, expected string
}{
{"blue/doc2.html", "<a href=\"%s/foobar.jpg\">Going</a>"},
{"sect/doc1.html", "<!doctype html><html><head></head><body><a href=\"#frag1\">link</a></body></html>"},
}
for _, test := range tests {
file, err := hugofs.Destination().Open(filepath.FromSlash(test.file))
if err != nil {
t.Fatalf("Unable to locate rendered content: %s", test.file)
}
content := helpers.ReaderToString(file)
expected := test.expected
if strings.Contains(expected, "%s") {
expected = fmt.Sprintf(expected, baseURL)
}
if !canonify {
expected = strings.Replace(expected, baseURL, "", -1)
}
if content != expected {
t.Errorf("AbsURLify with baseURL %q content expected:\n%q\ngot\n%q", baseURL, expected, content)
}
}
}
}
}
示例12: Publish
func (pp *PagePub) Publish(path string, r io.Reader) (err error) {
translated, err := pp.Translate(path)
if err != nil {
return
}
return helpers.WriteToDisk(translated, r, hugofs.Destination())
}
示例13: TestRobotsTXTOutput
func TestRobotsTXTOutput(t *testing.T) {
viper.Reset()
defer viper.Reset()
hugofs.InitMemFs()
viper.Set("baseurl", "http://auth/bub/")
viper.Set("enableRobotsTXT", true)
s := &Site{
Source: &source.InMemorySource{ByteSource: weightedSources},
}
s.initializeSiteInfo()
s.prepTemplates("robots.txt", robotTxtTemplate)
if err := s.createPages(); err != nil {
t.Fatalf("Unable to create pages: %s", err)
}
if err := s.buildSiteMeta(); err != nil {
t.Fatalf("Unable to build site metadata: %s", err)
}
if err := s.renderHomePage(); err != nil {
t.Fatalf("Unable to RenderHomePage: %s", err)
}
if err := s.renderSitemap(); err != nil {
t.Fatalf("Unable to RenderSitemap: %s", err)
}
if err := s.renderRobotsTXT(); err != nil {
t.Fatalf("Unable to RenderRobotsTXT :%s", err)
}
robotsFile, err := hugofs.Destination().Open("robots.txt")
if err != nil {
t.Fatalf("Unable to locate: robots.txt")
}
robots := helpers.ReaderToBytes(robotsFile)
if !bytes.HasPrefix(robots, []byte("User-agent: Googlebot")) {
t.Errorf("Robots file should start with 'User-agentL Googlebot'. %s", robots)
}
}
示例14: TestRenderThingOrDefault
func TestRenderThingOrDefault(t *testing.T) {
tests := []struct {
missing bool
template string
expected string
}{
{true, templateTitle, HTML("simple template")},
{true, templateFunc, HTML("simple-template")},
{false, templateTitle, HTML("simple template")},
{false, templateFunc, HTML("simple-template")},
}
hugofs.InitMemFs()
for i, test := range tests {
s := &Site{}
p, err := NewPageFrom(strings.NewReader(pageSimpleTitle), "content/a/file.md")
if err != nil {
t.Fatalf("Error parsing buffer: %s", err)
}
templateName := fmt.Sprintf("default%d", i)
s.prepTemplates(templateName, test.template)
var err2 error
if test.missing {
err2 = s.renderAndWritePage("name", "out", p, "missing", templateName)
} else {
err2 = s.renderAndWritePage("name", "out", p, templateName, "missing_default")
}
if err2 != nil {
t.Errorf("Unable to render html: %s", err)
}
file, err := hugofs.Destination().Open(filepath.FromSlash("out/index.html"))
if err != nil {
t.Errorf("Unable to open html: %s", err)
}
if helpers.ReaderToString(file) != test.expected {
t.Errorf("Content does not match. Expected '%s', got '%s'", test.expected, helpers.ReaderToString(file))
}
}
}
示例15: TestSitemapOutput
func TestSitemapOutput(t *testing.T) {
viper.Reset()
defer viper.Reset()
hugofs.InitMemFs()
viper.Set("baseurl", "http://auth/bub/")
s := &Site{
Source: &source.InMemorySource{ByteSource: weightedSources},
}
s.initializeSiteInfo()
s.prepTemplates("sitemap.xml", SITEMAP_TEMPLATE)
if err := s.createPages(); err != nil {
t.Fatalf("Unable to create pages: %s", err)
}
if err := s.buildSiteMeta(); err != nil {
t.Fatalf("Unable to build site metadata: %s", err)
}
if err := s.renderHomePage(); err != nil {
t.Fatalf("Unable to RenderHomePage: %s", err)
}
if err := s.renderSitemap(); err != nil {
t.Fatalf("Unable to RenderSitemap: %s", err)
}
if err := s.renderRobotsTXT(); err != nil {
t.Fatalf("Unable to RenderRobotsTXT :%s", err)
}
sitemapFile, err := hugofs.Destination().Open("sitemap.xml")
if err != nil {
t.Fatalf("Unable to locate: sitemap.xml")
}
sitemap := helpers.ReaderToBytes(sitemapFile)
if !bytes.HasPrefix(sitemap, []byte("<?xml")) {
t.Errorf("Sitemap file should start with <?xml. %s", sitemap)
}
}