Exemple #1
0
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
}
Exemple #2
0
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
}
Exemple #3
0
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
}
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
}
Exemple #5
0
func ProcessTemplate(page *gostatic.Page, args []string) error {
	if len(args) < 1 {
		return errors.New("'template' rule needs an argument")
	}
	pagetype := args[0]
	//todo catch thiss
	defer func() {
		if err := recover(); err != nil {
			//return err //errors.New(fmt.Sprintf("%s: %s", page.Source, err))
		}
	}()

	var buffer bytes.Buffer
	err := page.Site.Template.ExecuteTemplate(&buffer, pagetype, page)
	if err != nil {
		return errors.New(fmt.Sprintf("%s: %s", page.Source, err))
	}

	page.SetContent(buffer.String())
	return nil
}
Exemple #6
0
func ProcessMarkdown(page *gostatic.Page, args []string) error {
	result := Markdown(page.Content())
	page.SetContent(result)
	return nil
}