Пример #1
0
func (b basicPageHandler) Read(f *source.File, s *Site) HandledResult {
	page, err := NewPage(f.Path())
	if err != nil {
		return HandledResult{file: f, err: err}
	}

	if _, err := page.ReadFrom(f.Contents); err != nil {
		return HandledResult{file: f, err: err}
	}

	page.Site = &s.Info
	page.Tmpl = s.Tmpl

	return HandledResult{file: f, page: page, err: err}
}
Пример #2
0
// for non-pages in the site tree
func (s *SiteInfo) githubFileLink(ref string, currentPage *Page, relative bool) (string, error) {
	var refURL *url.URL
	var err error

	// TODO can I make this a param to `hugo --use-github-links=/docs`?
	// SVEN: add more tests - the prefix might be a real dir inside tho - add some pages that have it as a legitimate path
	repositoryPathPrefix := "/docs"

	refURL, err = url.Parse(strings.TrimPrefix(ref, repositoryPathPrefix))
	if err != nil {
		return "", err
	}

	if refURL.Scheme != "" {
		// TODO: consider looking for http(s?)://github.com/user/project/prefix and replacing it - tho this may be intentional, so idk
		//return "", fmt.Errorf("Not a plain filepath link (%s)", ref)
		// Treat this as not an error, as the link is used as-is
		return ref, nil
	}

	var target *source.File
	var link string

	if refURL.Path != "" {
		refPath := filepath.Clean(filepath.FromSlash(refURL.Path))

		if strings.IndexRune(refPath, os.PathSeparator) == 0 { // filepath.IsAbs fails to me.
			refPath = refPath[1:]
		} else {
			if currentPage != nil {
				refPath = filepath.Join(currentPage.Source.Dir(), refURL.Path)
			}
		}

		for _, file := range []*source.File(*s.Files) {
			if file.Path() == refPath {
				target = file
				break
			}
		}

		if target == nil {
			return "", fmt.Errorf("No file found for \"%s\" on page \"%s\".\n", ref, currentPage.Source.Path())
		}

		link = target.Path()
		// SVEN: look at filepath.Rel() it might help, got the rel/non-rel url's (dangerous tho)
		// SVEN: reconsider the fact I hardcoded the `relative` bool in both github resolvers
		if relative {
			return "./" + filepath.ToSlash(link), nil
		} else {
			return "/" + filepath.ToSlash(link), nil
		}
	}

	return "", fmt.Errorf("failed to find a file to match \"%s\" on page \"%s\"", ref, currentPage.Source.Path())
}
Пример #3
0
func (h cssHandler) FileConvert(f *source.File, s *Site) HandledResult {
	x := cssmin.Minify(f.Bytes())
	s.WriteDestFile(f.Path(), helpers.BytesToReader(x))
	return HandledResult{file: f}
}
Пример #4
0
func (h defaultHandler) FileConvert(f *source.File, s *Site) HandledResult {
	s.WriteDestFile(f.Path(), f.Contents)
	return HandledResult{file: f}
}