예제 #1
0
파일: site.go 프로젝트: lismore/hugo
// 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())
}
예제 #2
0
파일: site.go 프로젝트: dunn/hugo
func readData(f *source.File) (interface{}, error) {
	switch f.Extension() {
	case "yaml", "yml":
		return parser.HandleYamlMetaData(f.Bytes())
	case "json":
		return parser.HandleJsonMetaData(f.Bytes())
	case "toml":
		return parser.HandleTomlMetaData(f.Bytes())
	default:
		return nil, fmt.Errorf("Data not supported for extension '%s'", f.Extension())
	}
}
예제 #3
0
파일: site.go 프로젝트: maruel/hugo
func readData(f *source.File) (interface{}, error) {
	switch f.Extension() {
	case "yaml", "yml":
		return parser.HandleYAMLMetaData(f.Bytes())
	case "json":
		return parser.HandleJSONMetaData(f.Bytes())
	case "toml":
		return parser.HandleTOMLMetaData(f.Bytes())
	default:
		jww.WARN.Printf("Data not supported for extension '%s'", f.Extension())
		return nil, nil
	}
}
예제 #4
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}
}
예제 #5
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}
}
예제 #6
0
func (h defaultHandler) FileConvert(f *source.File, s *Site) HandledResult {
	s.WriteDestFile(f.Path(), f.Contents)
	return HandledResult{file: f}
}