當前位置: 首頁>>代碼示例>>Golang>>正文


Golang source.File類代碼示例

本文整理匯總了Golang中github.com/spf13/hugo/source.File的典型用法代碼示例。如果您正苦於以下問題:Golang File類的具體用法?Golang File怎麽用?Golang File使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了File類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: githubFileLink

// 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())
}
開發者ID:lismore,項目名稱:hugo,代碼行數:58,代碼來源:site.go

示例2: readData

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())
	}
}
開發者ID:dunn,項目名稱:hugo,代碼行數:12,代碼來源:site.go

示例3: readData

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
	}
}
開發者ID:maruel,項目名稱:hugo,代碼行數:13,代碼來源:site.go

示例4: Read

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}
}
開發者ID:johndunne,項目名稱:hugo,代碼行數:15,代碼來源:handler_page.go

示例5: FileConvert

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}
}
開發者ID:johndunne,項目名稱:hugo,代碼行數:5,代碼來源:handler_file.go


注:本文中的github.com/spf13/hugo/source.File類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。