本文整理匯總了Golang中github.com/piranha/gostatic/lib.Page.Content方法的典型用法代碼示例。如果您正苦於以下問題:Golang Page.Content方法的具體用法?Golang Page.Content怎麽用?Golang Page.Content使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/piranha/gostatic/lib.Page
的用法示例。
在下文中一共展示了Page.Content方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ProcessInnerTemplate
func ProcessInnerTemplate(page *gostatic.Page, args []string) error {
//todo catch
defer func() {
if err := recover(); err != nil {
//return fmt.Sprintf("%s: %s", page.Source, err)
}
}()
t, err := page.Site.Template.Clone()
if err != nil {
return err
}
t, err = t.New("ad-hoc").Parse(page.Content())
if err != nil {
return errors.New(fmt.Sprintf("Page %s: %s", page.Source, err))
}
var buffer bytes.Buffer
err = t.ExecuteTemplate(&buffer, "ad-hoc", page)
if err != nil {
return errors.New(fmt.Sprintf("Page %s: %s", page.Source, err))
}
page.SetContent(buffer.String())
return nil
}
示例2: ProcessExternal
func ProcessExternal(page *gostatic.Page, args []string) error {
if len(args) < 1 {
return errors.New("'external' rule needs a command name")
}
cmdName := args[0]
cmdArgs := args[1:]
path, err := exec.LookPath(cmdName)
if err != nil {
path, err = exec.LookPath(filepath.Join(page.Site.Base, cmdName))
if err != nil {
return fmt.Errorf("command '%s' not found", cmdName)
}
}
cmd := exec.Command(path, cmdArgs...)
cmd.Stdin = strings.NewReader(page.Content())
cmd.Dir = page.Site.Base
var stderr bytes.Buffer
cmd.Stderr = &stderr
data, err := cmd.Output()
if err != nil {
return fmt.Errorf("'%s' failed: %s\n%s",
strings.Join(args, " "), err, stderr.String())
}
page.SetContent(string(data))
return nil
}
示例3: ProcessRelativize
func ProcessRelativize(page *gostatic.Page, args []string) error {
repl := `$1="` + page.Rel("/") + `$2"`
rv := RelRe.ReplaceAllStringFunc(page.Content(), func(inp string) string {
if NonProtoRe.MatchString(inp) {
return inp
}
return RelRe.ReplaceAllString(inp, repl)
})
page.SetContent(rv)
return nil
}
示例4: ProcessConfig
func ProcessConfig(page *gostatic.Page, args []string) error {
parts := gostatic.TrimSplitN(page.Content(), "\n----\n", 2)
if len(parts) != 2 {
// no configuration, well then...
page.PageHeader = *gostatic.NewPageHeader()
return nil
}
page.PageHeader = *gostatic.ParseHeader(parts[0])
page.SetContent(parts[1])
return nil
}
示例5: checkPage
// Runs some checks against the parsed page.
func checkPage(t *testing.T, pageText string, page *gostatic.Page) {
if page.Content() != pageText {
t.Errorf("expected '%s', got '%s'", pageText, page.Content())
}
if len(page.PageHeader.Other) != 2 {
t.Errorf("expected length of 2, got '%d'", len(page.PageHeader.Other))
}
// Note: gostatic lib capitalizes the properties for some reason. So it
// converted 'salve' to 'Salve' etc.
salve := page.PageHeader.Other["Salve"]
if salve != "hello" {
t.Errorf("expected 'hello', got '%s'", salve)
}
munde := page.PageHeader.Other["Munde"]
if munde != "world" {
t.Errorf("expected 'world', got '%s'", munde)
}
}
示例6: ProcessMarkdown
func ProcessMarkdown(page *gostatic.Page, args []string) error {
result := Markdown(page.Content())
page.SetContent(result)
return nil
}