本文整理汇总了Golang中github.com/spf13/hugo/hugofs.Destination函数的典型用法代码示例。如果您正苦于以下问题:Golang Destination函数的具体用法?Golang Destination怎么用?Golang Destination使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Destination函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
}
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:30,代码来源:site_url_test.go
示例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)
}
}
}
开发者ID:vincentsys,项目名称:hugo,代码行数:50,代码来源:site_url_test.go
示例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)
}
开发者ID:tubo028,项目名称:hugo,代码行数:32,代码来源:hugo.go
示例4: destinationExists
func destinationExists(filename string) bool {
b, err := helpers.Exists(filename, hugofs.Destination())
if err != nil {
panic(err)
}
return b
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:7,代码来源:hugo_sites_test.go
示例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)
}
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:32,代码来源:server.go
示例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())
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:25,代码来源:htmlredirect.go
示例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)
}
}
}
开发者ID:tarsisazevedo,项目名称:hugo,代码行数:60,代码来源:handler_test.go
示例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)
}
}
开发者ID:tarsisazevedo,项目名称:hugo,代码行数:28,代码来源:robotstxt_test.go
示例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)
}
}
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:59,代码来源:site_test.go
示例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())
}
开发者ID:CowPanda,项目名称:hugo,代码行数:8,代码来源:file.go
示例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)
}
}
}
}
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:58,代码来源:site_test.go
示例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())
}
开发者ID:CODECOMMUNITY,项目名称:hugo,代码行数:9,代码来源:page.go
示例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)
}
}
开发者ID:XCMer,项目名称:hugo,代码行数:48,代码来源:robotstxt_test.go
示例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))
}
}
}
开发者ID:XCMer,项目名称:hugo,代码行数:47,代码来源:site_test.go
示例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)
}
}
开发者ID:XCMer,项目名称:hugo,代码行数:47,代码来源:sitemap_test.go
示例16: TestRSSOutput
func TestRSSOutput(t *testing.T) {
viper.Reset()
defer viper.Reset()
rssURI := "customrss.xml"
viper.Set("baseurl", "http://auth/bub/")
viper.Set("RSSUri", rssURI)
hugofs.InitMemFs()
s := &Site{
Source: &source.InMemorySource{ByteSource: weightedSources},
}
s.initializeSiteInfo()
s.prepTemplates("rss.xml", rssTemplate)
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)
}
file, err := hugofs.Destination().Open(rssURI)
if err != nil {
t.Fatalf("Unable to locate: %s", rssURI)
}
rss := helpers.ReaderToBytes(file)
if !bytes.HasPrefix(rss, []byte("<?xml")) {
t.Errorf("rss feed should start with <?xml. %s", rss)
}
}
开发者ID:CODECOMMUNITY,项目名称:hugo,代码行数:38,代码来源:rss_test.go
示例17: doTestSectionNaming
func doTestSectionNaming(t *testing.T, canonify, uglify, pluralize bool) {
hugofs.InitMemFs()
viper.Reset()
defer viper.Reset()
viper.Set("baseurl", "http://auth/sub/")
viper.Set("DefaultExtension", "html")
viper.Set("UglyURLs", uglify)
viper.Set("PluralizeListTitles", pluralize)
viper.Set("CanonifyURLs", canonify)
var expectedPathSuffix string
if uglify {
expectedPathSuffix = ".html"
} else {
expectedPathSuffix = "/index.html"
}
sources := []source.ByteSource{
{filepath.FromSlash("sect/doc1.html"), []byte("doc1")},
{filepath.FromSlash("Fish and Chips/doc2.html"), []byte("doc2")},
{filepath.FromSlash("ラーメン/doc3.html"), []byte("doc3")},
}
s := &Site{
Source: &source.InMemorySource{ByteSource: sources},
targets: targetList{page: &target.PagePub{UglyURLs: uglify}},
}
s.initializeSiteInfo()
s.prepTemplates(
"_default/single.html", "{{.Content}}",
"_default/list.html", "{{ .Title }}")
createAndRenderPages(t, s)
s.renderSectionLists()
tests := []struct {
doc string
pluralAware bool
expected string
}{
{filepath.FromSlash(fmt.Sprintf("sect/doc1%s", expectedPathSuffix)), false, "doc1"},
{filepath.FromSlash(fmt.Sprintf("sect%s", expectedPathSuffix)), true, "Sect"},
{filepath.FromSlash(fmt.Sprintf("fish-and-chips/doc2%s", expectedPathSuffix)), false, "doc2"},
{filepath.FromSlash(fmt.Sprintf("fish-and-chips%s", expectedPathSuffix)), true, "Fish and Chips"},
{filepath.FromSlash(fmt.Sprintf("ラーメン/doc3%s", expectedPathSuffix)), false, "doc3"},
{filepath.FromSlash(fmt.Sprintf("ラーメン%s", expectedPathSuffix)), true, "ラーメン"},
}
for _, test := range tests {
file, err := hugofs.Destination().Open(test.doc)
if err != nil {
t.Fatalf("Did not find %s in target: %s", test.doc, err)
}
content := helpers.ReaderToString(file)
if test.pluralAware && pluralize {
test.expected = inflect.Pluralize(test.expected)
}
if content != test.expected {
t.Errorf("%s content expected:\n%q\ngot:\n%q", test.doc, test.expected, content)
}
}
}
开发者ID:XCMer,项目名称:hugo,代码行数:68,代码来源:site_test.go
示例18: doTestShouldAlwaysHaveUglyURLs
func doTestShouldAlwaysHaveUglyURLs(t *testing.T, uglyURLs bool) {
viper.Reset()
defer viper.Reset()
viper.Set("DefaultExtension", "html")
viper.Set("verbose", true)
viper.Set("baseurl", "http://auth/bub")
viper.Set("DisableSitemap", false)
viper.Set("DisableRSS", false)
viper.Set("RSSUri", "index.xml")
viper.Set("blackfriday",
map[string]interface{}{
"plainIDAnchors": true})
viper.Set("UglyURLs", uglyURLs)
sources := []source.ByteSource{
{filepath.FromSlash("sect/doc1.md"), []byte("---\nmarkup: markdown\n---\n# title\nsome *content*")},
{filepath.FromSlash("sect/doc2.md"), []byte("---\nurl: /ugly.html\nmarkup: markdown\n---\n# title\ndoc2 *content*")},
}
s := &Site{
Source: &source.InMemorySource{ByteSource: sources},
targets: targetList{page: &target.PagePub{UglyURLs: uglyURLs}},
}
s.initializeSiteInfo()
s.prepTemplates(
"index.html", "Home Sweet {{ if.IsHome }}Home{{ end }}.",
"_default/single.html", "{{.Content}}{{ if.IsHome }}This is not home!{{ end }}",
"404.html", "Page Not Found.{{ if.IsHome }}This is not home!{{ end }}",
"rss.xml", "<root>RSS</root>",
"sitemap.xml", "<root>SITEMAP</root>")
createAndRenderPages(t, s)
s.renderHomePage()
s.renderSitemap()
var expectedPagePath string
if uglyURLs {
expectedPagePath = "sect/doc1.html"
} else {
expectedPagePath = "sect/doc1/index.html"
}
tests := []struct {
doc string
expected string
}{
{filepath.FromSlash("index.html"), "Home Sweet Home."},
{filepath.FromSlash(expectedPagePath), "\n\n<h1 id=\"title\">title</h1>\n\n<p>some <em>content</em></p>\n"},
{filepath.FromSlash("404.html"), "Page Not Found."},
{filepath.FromSlash("index.xml"), "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n<root>RSS</root>"},
{filepath.FromSlash("sitemap.xml"), "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n<root>SITEMAP</root>"},
// Issue #1923
{filepath.FromSlash("ugly.html"), "\n\n<h1 id=\"title\">title</h1>\n\n<p>doc2 <em>content</em></p>\n"},
}
for _, p := range s.Pages {
assert.False(t, p.IsHome)
}
for _, test := range tests {
file, err := hugofs.Destination().Open(test.doc)
if err != nil {
t.Fatalf("Did not find %s in target: %s", test.doc, err)
}
content := helpers.ReaderToString(file)
if content != test.expected {
t.Errorf("%s content expected:\n%q\ngot:\n%q", test.doc, test.expected, content)
}
}
}
开发者ID:XCMer,项目名称:hugo,代码行数:77,代码来源:site_test.go
示例19: doTestCrossrefs
func doTestCrossrefs(t *testing.T, relative, uglyURLs bool) {
viper.Reset()
defer viper.Reset()
baseURL := "http://foo/bar"
viper.Set("DefaultExtension", "html")
viper.Set("baseurl", baseURL)
viper.Set("UglyURLs", uglyURLs)
viper.Set("verbose", true)
var refShortcode string
var expectedBase string
var expectedURLSuffix string
var expectedPathSuffix string
if relative {
refShortcode = "relref"
expectedBase = "/bar"
} else {
refShortcode = "ref"
expectedBase = baseURL
}
if uglyURLs {
expectedURLSuffix = ".html"
expectedPathSuffix = ".html"
} else {
expectedURLSuffix = "/"
expectedPathSuffix = "/index.html"
}
sources := []source.ByteSource{
{filepath.FromSlash("sect/doc1.md"),
[]byte(fmt.Sprintf(`Ref 2: {{< %s "sect/doc2.md" >}}`, refShortcode))},
// Issue #1148: Make sure that no P-tags is added around shortcodes.
{filepath.FromSlash("sect/doc2.md"),
[]byte(fmt.Sprintf(`**Ref 1:**
{{< %s "sect/doc1.md" >}}
THE END.`, refShortcode))},
// Issue #1753: Should not add a trailing newline after shortcode.
{filepath.FromSlash("sect/doc3.md"),
[]byte(fmt.Sprintf(`**Ref 1:**{{< %s "sect/doc3.md" >}}.`, refShortcode))},
}
s := &Site{
Source: &source.InMemorySource{ByteSource: sources},
targets: targetList{page: &target.PagePub{UglyURLs: uglyURLs}},
}
s.initializeSiteInfo()
s.prepTemplates("_default/single.html", "{{.Content}}")
createAndRenderPages(t, s)
tests := []struct {
doc string
expected string
}{
{filepath.FromSlash(fmt.Sprintf("sect/doc1%s", expectedPathSuffix)), fmt.Sprintf("<p>Ref 2: %s/sect/doc2%s</p>\n", expectedBase, expectedURLSuffix)},
{filepath.FromSlash(fmt.Sprintf("sect/doc2%s", expectedPathSuffix)), fmt.Sprintf("<p><strong>Ref 1:</strong></p>\n\n%s/sect/doc1%s\n\n<p>THE END.</p>\n", expectedBase, expectedURLSuffix)},
{filepath.FromSlash(fmt.Sprintf("sect/doc3%s", expectedPathSuffix)), fmt.Sprintf("<p><strong>Ref 1:</strong>%s/sect/doc3%s.</p>\n", expectedBase, expectedURLSuffix)},
}
for _, test := range tests {
file, err := hugofs.Destination().Open(test.doc)
if err != nil {
t.Fatalf("Did not find %s in target: %s", test.doc, err)
}
content := helpers.ReaderToString(file)
if content != test.expected {
t.Errorf("%s content expected:\n%q\ngot:\n%q", test.doc, test.expected, content)
}
}
}
开发者ID:XCMer,项目名称:hugo,代码行数:81,代码来源:site_test.go
示例20: TestShortcodesInSite
//.........这里部分代码省略.........
filepath.FromSlash("sect/doc6/index.html"),
"b: b c: c\n</code></pre></div>\n"},
// #2249
{"sect/doc7.ad", `_Shortcodes:_ *b: {{< b >}} c: {{% c %}}*`,
filepath.FromSlash("sect/doc7/index.html"),
"<div class=\"paragraph\">\n<p><em>Shortcodes:</em> <strong>b: b c: c</strong></p>\n</div>\n"},
{"sect/doc8.rst", `**Shortcodes:** *b: {{< b >}} c: {{% c %}}*`,
filepath.FromSlash("sect/doc8/index.html"),
"<div class=\"document\">\n\n\n<p><strong>Shortcodes:</strong> <em>b: b c: c</em></p>\n</div>"},
{"sect/doc9.mmark", `
---
menu:
main:
parent: 'parent'
---
**Shortcodes:** *b: {{< b >}} c: {{% c %}}*`,
filepath.FromSlash("sect/doc9/index.html"),
"<p><strong>Shortcodes:</strong> <em>b: b c: c</em></p>\n"},
// Issue #1229: Menus not available in shortcode.
{"sect/doc10.md", `---
menu:
main:
identifier: 'parent'
tags:
- Menu
---
**Menus:** {{< menu >}}`,
filepath.FromSlash("sect/doc10/index.html"),
"<p><strong>Menus:</strong> 1</p>\n"},
// Issue #2323: Taxonomies not available in shortcode.
{"sect/doc11.md", `---
tags:
- Bugs
---
**Tags:** {{< tags >}}`,
filepath.FromSlash("sect/doc11/index.html"),
"<p><strong>Tags:</strong> 2</p>\n"},
}
sources := make([]source.ByteSource, len(tests))
for i, test := range tests {
sources[i] = source.ByteSource{Name: filepath.FromSlash(test.contentPath), Content: []byte(test.content)}
}
s := &Site{
Source: &source.InMemorySource{ByteSource: sources},
targets: targetList{page: &target.PagePub{UglyURLs: false}},
Language: helpers.NewDefaultLanguage(),
}
addTemplates := func(templ tpl.Template) error {
templ.AddTemplate("_default/single.html", "{{.Content}}")
templ.AddInternalShortcode("b.html", `b`)
templ.AddInternalShortcode("c.html", `c`)
templ.AddInternalShortcode("d.html", `d`)
templ.AddInternalShortcode("menu.html", `{{ len (index .Page.Menus "main").Children }}`)
templ.AddInternalShortcode("tags.html", `{{ len .Page.Site.Taxonomies.tags }}`)
return nil
}
sites, err := newHugoSites(s)
if err != nil {
t.Fatalf("Failed to build site: %s", err)
}
if err = sites.Build(BuildCfg{withTemplate: addTemplates}); err != nil {
t.Fatalf("Failed to build site: %s", err)
}
for _, test := range tests {
if strings.HasSuffix(test.contentPath, ".ad") && !helpers.HasAsciidoc() {
fmt.Println("Skip Asciidoc test case as no Asciidoc present.")
continue
} else if strings.HasSuffix(test.contentPath, ".rst") && !helpers.HasRst() {
fmt.Println("Skip Rst test case as no rst2html present.")
continue
} else if strings.Contains(test.expected, "code") && !helpers.HasPygments() {
fmt.Println("Skip Pygments test case as no pygments present.")
continue
}
file, err := hugofs.Destination().Open(test.outFile)
if err != nil {
t.Fatalf("Did not find %s in target: %s", test.outFile, err)
}
content := helpers.ReaderToString(file)
if !strings.Contains(content, test.expected) {
t.Fatalf("%s content expected:\n%q\ngot:\n%q", test.outFile, test.expected, content)
}
}
}
开发者ID:tarsisazevedo,项目名称:hugo,代码行数:101,代码来源:shortcode_test.go
注:本文中的github.com/spf13/hugo/hugofs.Destination函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论