2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
2016-11-01 18:04:12 -04:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package hugolib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/bep/gitmap"
|
2018-03-11 13:59:11 -04:00
|
|
|
"github.com/gohugoio/hugo/config"
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/resources/page"
|
2016-11-01 18:04:12 -04:00
|
|
|
)
|
|
|
|
|
2018-03-11 13:59:11 -04:00
|
|
|
type gitInfo struct {
|
|
|
|
contentDir string
|
|
|
|
repo *gitmap.GitRepo
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (g *gitInfo) forPage(p page.Page) *gitmap.GitInfo {
|
|
|
|
name := strings.TrimPrefix(filepath.ToSlash(p.File().Filename()), g.contentDir)
|
2018-08-11 10:37:00 -04:00
|
|
|
name = strings.TrimPrefix(name, "/")
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
return g.repo.Files[name]
|
2018-03-11 13:59:11 -04:00
|
|
|
}
|
2016-11-01 18:04:12 -04:00
|
|
|
|
2018-03-11 13:59:11 -04:00
|
|
|
func newGitInfo(cfg config.Provider) (*gitInfo, error) {
|
2018-08-11 10:37:00 -04:00
|
|
|
workingDir := cfg.GetString("workingDir")
|
2016-11-01 18:04:12 -04:00
|
|
|
|
|
|
|
gitRepo, err := gitmap.Map(workingDir, "")
|
|
|
|
if err != nil {
|
2018-03-11 13:59:11 -04:00
|
|
|
return nil, err
|
2016-11-01 18:04:12 -04:00
|
|
|
}
|
|
|
|
|
2018-08-11 10:37:00 -04:00
|
|
|
return &gitInfo{contentDir: gitRepo.TopLevelAbsPath, repo: gitRepo}, nil
|
2016-11-01 18:04:12 -04:00
|
|
|
}
|