**/go.sum
**/go.mod
- name: Install Ruby
- uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4
+ uses: ruby/setup-ruby@036ef458ddccddb148a2b9fb67e95a22fdbf728b
with:
ruby-version: '2.7'
bundler-cache: true #
**/go.sum
**/go.mod
- name: Install Ruby
- uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4
+ uses: ruby/setup-ruby@036ef458ddccddb148a2b9fb67e95a22fdbf728b
with:
ruby-version: '2.7'
bundler-cache: true #
package herrors
import (
- "bytes"
"errors"
"fmt"
"io"
"os"
"runtime"
"runtime/debug"
- "strconv"
)
// PrintStackTrace prints the current stacktrace to w.
}
}
-// GetGID the current goroutine id. Used only for debugging.
-func GetGID() uint64 {
- b := make([]byte, 64)
- b = b[:runtime.Stack(b, false)]
- b = bytes.TrimPrefix(b, []byte("goroutine "))
- b = b[:bytes.IndexByte(b, ' ')]
- n, _ := strconv.ParseUint(string(b), 10, 64)
- return n
-}
-
// IsFeatureNotAvailableError returns true if the given error is or contains a FeatureNotAvailableError.
func IsFeatureNotAvailableError(err error) bool {
return errors.Is(err, &FeatureNotAvailableError{})
sd := cfg.Get(key)
return types.ToStringSlicePreserveString(sd)
}
-
-func setIfNotSet(cfg Provider, key string, value any) {
- if !cfg.IsSet(key) {
- cfg.Set(key, value)
- }
-}
func isEndOfSentence(r rune) bool {
return r == '.' || r == '?' || r == '!' || r == '"' || r == '\n'
}
-
-// Kept only for benchmark.
-func (c *ContentSpec) truncateWordsToWholeSentenceOld(content string) (string, bool) {
- words := strings.Fields(content)
-
- if c.Cfg.SummaryLength() >= len(words) {
- return strings.Join(words, " "), false
- }
-
- for counter, word := range words[c.Cfg.SummaryLength():] {
- if strings.HasSuffix(word, ".") ||
- strings.HasSuffix(word, "?") ||
- strings.HasSuffix(word, ".\"") ||
- strings.HasSuffix(word, "!") {
- upper := c.Cfg.SummaryLength() + counter + 1
- return strings.Join(words[:upper], " "), (upper < len(words))
- }
- }
-
- return strings.Join(words[:c.Cfg.SummaryLength()], " "), true
-}
emojiMaxSize int
)
-// Emoji returns the emoji given a key, e.g. ":smile:", nil if not found.
-func Emoji(key string) []byte {
- emojiInit.Do(initEmoji)
- return emojis[key]
-}
-
// Emojify "emojifies" the input source.
// Note that the input byte slice will be modified if needed.
// See http://www.emoji-cheat-sheet.com/
"github.com/jdkato/prose/transform"
bp "github.com/gohugoio/hugo/bufferpool"
- "github.com/spf13/pflag"
)
// FilePathSeparator as defined by os.Separator.
return r == ' ' || r == '\t' || r == '\n' || r == '\r'
}
-// NormalizeHugoFlags facilitates transitions of Hugo command-line flags,
-// e.g. --baseUrl to --baseURL, --uglyUrls to --uglyURLs
-func NormalizeHugoFlags(f *pflag.FlagSet, name string) pflag.NormalizedName {
- switch name {
- case "baseUrl":
- name = "baseURL"
- case "uglyUrls":
- name = "uglyURLs"
- }
- return pflag.NormalizedName(name)
-}
-
// PrintFs prints the given filesystem to the given writer starting from the given path.
// This is useful for debugging.
func PrintFs(fs afero.Fs, path string, w io.Writer) {
+++ /dev/null
-// Copyright 2018 The Hugo Authors. All rights reserved.
-//
-// 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 htesting
-
-import (
- "path/filepath"
- "testing"
-
- "github.com/spf13/afero"
-)
-
-type testFile struct {
- name string
- content string
-}
-
-type testdataBuilder struct {
- t testing.TB
- fs afero.Fs
- workingDir string
-
- files []testFile
-}
-
-func NewTestdataBuilder(fs afero.Fs, workingDir string, t testing.TB) *testdataBuilder {
- workingDir = filepath.Clean(workingDir)
- return &testdataBuilder{fs: fs, workingDir: workingDir, t: t}
-}
-
-func (b *testdataBuilder) Add(filename, content string) *testdataBuilder {
- b.files = append(b.files, testFile{name: filename, content: content})
- return b
-}
-
-func (b *testdataBuilder) Build() *testdataBuilder {
- for _, f := range b.files {
- if err := afero.WriteFile(b.fs, filepath.Join(b.workingDir, f.name), []byte(f.content), 0666); err != nil {
- b.t.Fatalf("failed to add %q: %s", f.name, err)
- }
- }
- return b
-}
-
-func (b testdataBuilder) WithWorkingDir(dir string) *testdataBuilder {
- b.workingDir = filepath.Clean(dir)
- b.files = make([]testFile, 0)
- return &b
-}
package hugofs
import (
+ "errors"
"os"
"path/filepath"
"reflect"
"github.com/gohugoio/hugo/hugofs/files"
"golang.org/x/text/unicode/norm"
- "errors"
-
"github.com/gohugoio/hugo/common/hreflect"
"github.com/gohugoio/hugo/common/htime"
func decorateFileInfo(
fi os.FileInfo,
fs afero.Fs, opener func() (afero.File, error),
- filename, filepath string, inMeta *FileMeta) FileMetaInfo {
+ filename, filepath string, inMeta *FileMeta,
+) FileMetaInfo {
var meta *FileMeta
var fim FileMetaInfo
return names
}
-func fromSlash(filenames []string) []string {
- for i, name := range filenames {
- filenames[i] = filepath.FromSlash(name)
- }
- return filenames
-}
-
func sortFileInfos(fis []os.FileInfo) {
sort.Slice(fis, func(i, j int) bool {
fimi, fimj := fis[i].(FileMetaInfo), fis[j].(FileMetaInfo)
"github.com/spf13/afero"
)
-var (
- _ FilesystemUnwrapper = (*filenameFilterFs)(nil)
-)
+var _ FilesystemUnwrapper = (*filenameFilterFs)(nil)
func newFilenameFilterFs(fs afero.Fs, base string, filter *glob.FilenameFilter) afero.Fs {
return &filenameFilterFs{
return fi, err
}
-func (fs *filenameFilterFs) getOpener(name string) func() (afero.File, error) {
- return func() (afero.File, error) {
- return fs.Open(name)
- }
-}
-
type filenameFilterDir struct {
afero.File
base string
func (fs *filenameFilterFs) Rename(o, n string) error {
return syscall.EPERM
}
+
func (fs *filenameFilterFs) Create(n string) (afero.File, error) {
return nil, syscall.EPERM
}
+
func (fs *filenameFilterFs) Name() string {
return "FinameFilterFS"
}
WorkingDirWritable afero.Fs
}
-// NewDefault creates a new Fs with the OS file system
-// as source and destination file systems.
-func NewDefault(conf config.BaseConfig) *Fs {
- fs := Os
- return NewFrom(fs, conf)
-}
-
-func NewDefaultOld(cfg config.Provider) *Fs {
+func NewDefault(cfg config.Provider) *Fs {
workingDir, publishDir := getWorkingPublishDir(cfg)
fs := Os
return newFs(fs, fs, workingDir, publishDir)
publishDir = cfg.GetString("publishDir")
}
return workingDir, publishDir
-
}
func newFs(source, destination afero.Fs, workingDir, publishDir string) *Fs {
}
if info.IsDir() {
counter++
- fs.Chmod(path, 0777)
+ fs.Chmod(path, 0o777)
}
return nil
})
if WalkFilesystems(afs.UnwrapFilesystem(), fn) {
return true
}
-
} else if bfs, ok := fs.(FilesystemsUnwrapper); ok {
for _, sf := range bfs.UnwrapFilesystems() {
if WalkFilesystems(sf, fn) {
c.Assert(IsOsFs(&afero.MemMapFs{}), qt.Equals, false)
c.Assert(IsOsFs(afero.NewBasePathFs(&afero.MemMapFs{}, "/public")), qt.Equals, false)
c.Assert(IsOsFs(afero.NewBasePathFs(Os, t.TempDir())), qt.Equals, true)
-
}
func TestNewDefault(t *testing.T) {
v := config.New()
v.Set("workingDir", t.TempDir())
v.Set("publishDir", "public")
- f := NewDefaultOld(v)
+ f := NewDefault(v)
c.Assert(f.Source, qt.IsNotNil)
c.Assert(f.Source, hqt.IsSameType, new(afero.OsFs))
// to underline that even if they can be composites, they all have a base path set to a specific
// resource folder, e.g "/my-project/content". So, no absolute filenames needed.
type BaseFs struct {
-
// SourceFilesystems contains the different source file systems.
*SourceFilesystems
return filename, filepath.Join(meta.Filename, filename), nil
}
}
-
}
return "", "", fmt.Errorf("could not determine content directory for %q", filename)
},
},
)
-
}
// StaticFs returns the static filesystem for the given language.
func (b *sourceFilesystemsBuilder) createOverlayFs(
collector *filesystemsCollector,
- mounts []mountsDescriptor) error {
-
+ mounts []mountsDescriptor,
+) error {
if len(mounts) == 0 {
appendNopIfEmpty := func(ofs *overlayfs.OverlayFs) *overlayfs.OverlayFs {
if ofs.NumFilesystems() > 0 {
}
}
-func (c *filesystemsCollector) reverseFis(fis []hugofs.FileMetaInfo) {
- for i := len(fis)/2 - 1; i >= 0; i-- {
- opp := len(fis) - 1 - i
- fis[i], fis[opp] = fis[opp], fis[i]
- }
-}
-
type mountsDescriptor struct {
modules.Module
dir string
b := newTestSitesBuilder(t)
tempDir := t.TempDir()
workingDir := filepath.Join(tempDir, "myhugosite")
- b.Assert(os.MkdirAll(workingDir, 0777), qt.IsNil)
+ b.Assert(os.MkdirAll(workingDir, 0o777), qt.IsNil)
cfg := config.New()
cfg.Set("workingDir", workingDir)
cfg.Set("publishDir", "public")
- b.Fs = hugofs.NewDefaultOld(cfg)
+ b.Fs = hugofs.NewDefault(cfg)
b.WithWorkingDir(workingDir).WithConfigFile("toml", createConfig(workingDir, moduleOpts))
b.WithTemplates(
"index.html", `
b := newTestSitesBuilder(t)
// Need to use OS fs for this.
- b.Fs = hugofs.NewDefaultOld(v)
+ b.Fs = hugofs.NewDefault(v)
b.WithWorkingDir(workingDir).WithConfigFile("toml", config)
b.WithContent("page.md", `
createDirsAndFiles := func(baseDir string) {
for _, dir := range files.ComponentFolders {
realDir := filepath.Join(baseDir, dir, "real")
- c.Assert(os.MkdirAll(realDir, 0777), qt.IsNil)
- c.Assert(afero.WriteFile(fs.Source, filepath.Join(realDir, "data.toml"), []byte("[hello]\nother = \"hello\""), 0777), qt.IsNil)
+ c.Assert(os.MkdirAll(realDir, 0o777), qt.IsNil)
+ c.Assert(afero.WriteFile(fs.Source, filepath.Join(realDir, "data.toml"), []byte("[hello]\nother = \"hello\""), 0o777), qt.IsNil)
}
- c.Assert(afero.WriteFile(fs.Source, filepath.Join(baseDir, "layouts", "index.html"), []byte(homeTemplate), 0777), qt.IsNil)
+ c.Assert(afero.WriteFile(fs.Source, filepath.Join(baseDir, "layouts", "index.html"), []byte(homeTemplate), 0o777), qt.IsNil)
}
// Create project dirs and files.
cfg.Set("workingDir", workingDir)
cfg.Set("publishDir", "public")
- b.Fs = hugofs.NewDefaultOld(cfg)
+ b.Fs = hugofs.NewDefault(cfg)
b.WithWorkingDir(workingDir).WithConfigFile("toml", tomlConfig)
b.WithTemplatesAdded("index.html", `
<a href="{{ $link | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if $isRemote }} target="_blank"{{ end }}>{{ .Text | safeHTML }}</a>
`)
- os.Mkdir(filepath.Join(workingDir, "mycontent"), 0777)
- os.Mkdir(filepath.Join(workingDir, "mycontent", "mybundle"), 0777)
+ os.Mkdir(filepath.Join(workingDir, "mycontent"), 0o777)
+ os.Mkdir(filepath.Join(workingDir, "mycontent", "mybundle"), 0o777)
b.WithSourceFile("README.md", `---
title: "Readme Title"
cfg := config.New()
cfg.Set("workingDir", workingDir)
cfg.Set("publishDir", "public")
- b.Fs = hugofs.NewDefaultOld(cfg)
+ b.Fs = hugofs.NewDefault(cfg)
- os.MkdirAll(filepath.Join(workingDir, "content", "blog"), 0777)
+ os.MkdirAll(filepath.Join(workingDir, "content", "blog"), 0o777)
b.WithWorkingDir(workingDir).WithConfigFile("toml", tomlConfig)
defer test.clean()
subContentDir := filepath.Join(test.workingDir, "mycontent", "sub")
- os.MkdirAll(subContentDir, 0777)
+ os.MkdirAll(subContentDir, 0o777)
myPartialsDir := filepath.Join(test.workingDir, "subdir", "mypartials")
- os.MkdirAll(myPartialsDir, 0777)
+ os.MkdirAll(myPartialsDir, 0o777)
absShortcodesDir := filepath.Join(absDir, "abs", "myshortcodes")
- os.MkdirAll(absShortcodesDir, 0777)
+ os.MkdirAll(absShortcodesDir, 0o777)
b.WithSourceFile("README.md", "---\ntitle: Readme\n---")
b.WithSourceFile("mycontent/sub/p1.md", "---\ntitle: P1\n---")
---
Content.
-`), 0777)
+`), 0o777)
b.WithWorkingDir(workDir).WithConfigFile("toml", config)
b.WithContent("dummy.md", "")
"github.com/gohugoio/hugo/resources/kinds"
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/page/pagemeta"
- "github.com/gohugoio/hugo/tpl"
)
// HugoSites represents the sites to build. Each site represents a language.
return nil
}
-func (s *Site) withSiteTemplates(withTemplates ...func(templ tpl.TemplateManager) error) func(templ tpl.TemplateManager) error {
- return func(templ tpl.TemplateManager) error {
- for _, wt := range withTemplates {
- if wt == nil {
- continue
- }
- if err := wt(templ); err != nil {
- return err
- }
- }
-
- return nil
- }
-}
-
// Reset resets the sites and template caches etc., making it ready for a full rebuild.
func (h *HugoSites) reset(config *BuildCfg) {
if config.ResetState {
realFilename := fim.Meta().Filename
return herrors.NewFileErrorFromFile(err, realFilename, h.SourceSpec.Fs.Source, nil)
-
}
func (h *HugoSites) readData(f source.File) (any, error) {
return p.Title()
}
-func (p *pageState) posFromPage(offset int) text.Position {
- return p.posFromInput(p.source.parsed.Input(), offset)
-}
-
func (p *pageState) posFromInput(input []byte, offset int) text.Position {
if offset < 0 {
return text.Position{
return prerenderedShortcode{s: result, hasVariants: hasVariants}, err
}
-func (s *shortcodeHandler) hasShortcodes() bool {
- return s != nil && len(s.shortcodes) > 0
-}
-
func (s *shortcodeHandler) addName(name string) {
s.nameSetMu.Lock()
defer s.nameSetMu.Unlock()
return rendered, nil
}
-func (s *shortcodeHandler) parseError(err error, input []byte, pos int) error {
- if s.p != nil {
- return s.p.parseError(err, input, pos)
- }
- return err
-}
-
// pageTokens state:
// - before: positioned just before the shortcode start
// - after: shortcode(s) consumed (plural when they are nested)
import (
"fmt"
"path/filepath"
- "strings"
"testing"
"github.com/gohugoio/hugo/config"
}
}
-func ident(level int) string {
- return strings.Repeat(" ", level)
-}
-
func TestPartialInline(t *testing.T) {
b := newTestSitesBuilder(t)
"github.com/spf13/cast"
"github.com/gohugoio/hugo/helpers"
- "github.com/gohugoio/hugo/tpl"
"github.com/gohugoio/hugo/resources/resource"
"data",
"i18n",
} {
- if err := os.MkdirAll(filepath.Join(s.workingDir, dir), 0777); err != nil {
+ if err := os.MkdirAll(filepath.Join(s.workingDir, dir), 0o777); err != nil {
return fmt.Errorf("failed to create %q: %w", dir, err)
}
}
depsCfg.TestLogger = s.logger
sites, err := NewHugoSites(depsCfg)
-
if err != nil {
return fmt.Errorf("failed to create sites: %w", err)
}
}
}
-func (th testHelper) assertFileContentRegexp(filename string, matches ...string) {
- filename = th.replaceDefaultContentLanguageValue(filename)
- content := readWorkingDir(th, th.Fs, filename)
- for _, match := range matches {
- match = th.replaceDefaultContentLanguageValue(match)
- r := regexp.MustCompile(match)
- matches := r.MatchString(content)
- if !matches {
- fmt.Println("Expected to match regexp:\n"+match+"\nGot:\n", content)
- }
- th.Assert(matches, qt.Equals, true)
- }
-}
-
func (th testHelper) assertFileNotExist(filename string) {
exists, err := helpers.Exists(filename, th.Fs.PublishDir)
th.Assert(err, qt.IsNil)
return value
}
-func loadTestConfig(fs afero.Fs) (*allconfig.Configs, error) {
- res, err := allconfig.LoadConfig(allconfig.ConfigSourceDescriptor{Fs: fs})
- return res, err
-}
-
func loadTestConfigFromProvider(cfg config.Provider) (*allconfig.Configs, error) {
workingDir := cfg.GetString("workingDir")
fs := afero.NewMemMapFs()
if workingDir != "" {
- fs.MkdirAll(workingDir, 0755)
+ fs.MkdirAll(workingDir, 0o755)
}
res, err := allconfig.LoadConfig(allconfig.ConfigSourceDescriptor{Flags: cfg, Fs: fs})
return res, err
return th, h
}
-func createWithTemplateFromNameValues(additionalTemplates ...string) func(templ tpl.TemplateManager) error {
- return func(templ tpl.TemplateManager) error {
- for i := 0; i < len(additionalTemplates); i += 2 {
- err := templ.AddTemplate(additionalTemplates[i], additionalTemplates[i+1])
- if err != nil {
- return err
- }
- }
- return nil
- }
-}
-
// TODO(bep) replace these with the builder
func buildSingleSite(t testing.TB, depsCfg deps.DepsCfg, buildCfg BuildCfg) *Site {
t.Helper()
RefreshPath("/x.js")
}
-// NavigateToPath tells livereload to navigate to the given path.
-// This translates to `window.location.href = path` in the client.
-func NavigateToPath(path string) {
- RefreshPath(hugoNavigatePrefix + path)
-}
-
// NavigateToPathForPort is similar to NavigateToPath but will also
// set window.location.port to the given port value.
func NavigateToPathForPort(path string, port int) {
package images
import (
- "github.com/yuin/goldmark"
"github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/text"
- "github.com/yuin/goldmark/util"
)
type (
AttrIsBlock = "_h__isBlock"
)
-func New(wrapStandAloneImageWithinParagraph bool) goldmark.Extender {
- return &linksExtension{wrapStandAloneImageWithinParagraph: wrapStandAloneImageWithinParagraph}
-}
-
-func (e *linksExtension) Extend(m goldmark.Markdown) {
- m.Parser().AddOptions(
- parser.WithASTTransformers(
- util.Prioritized(&Transformer{wrapStandAloneImageWithinParagraph: e.wrapStandAloneImageWithinParagraph}, 300),
- ),
- )
-}
-
type Transformer struct {
wrapStandAloneImageWithinParagraph bool
}
}
return ast.WalkContinue, nil
-
})
-
}
return ``
},
}
-
} else {
wrapper = getPreWrapper(lang, w)
}
return s.end(code)
}
-func WritePreEnd(w io.Writer) {
- fmt.Fprint(w, preEnd)
-}
-
func writeDivStart(w hugio.FlexiWriter, attrs []attributes.Attribute) {
w.WriteString(`<div class="highlight`)
if attrs != nil {
var DefaultTypes Types
func init() {
-
ns, err := DecodeTypes(nil)
if err != nil {
panic(err)
// DecodeTypes decodes the given map of media types.
func DecodeTypes(in map[string]any) (*config.ConfigNamespace[map[string]MediaTypeConfig, Types], error) {
-
buildConfig := func(v any) (Types, any, error) {
m, err := maps.ToStringMapE(v)
if err != nil {
return nil, fmt.Errorf("failed to decode media types: %w", err)
}
return ns, nil
-
-}
-
-func suffixIsRemoved() error {
- return errors.New(`MediaType.Suffix is removed. Before Hugo 0.44 this was used both to set a custom file suffix and as way
-to augment the mediatype definition (what you see after the "+", e.g. "image/svg+xml").
-
-This had its limitations. For one, it was only possible with one file extension per MIME type.
-
-Now you can specify multiple file suffixes using "suffixes", but you need to specify the full MIME type
-identifier:
-
-[mediaTypes]
-[mediaTypes."image/svg+xml"]
-suffixes = ["svg", "abc" ]
-
-In most cases, it will be enough to just change:
-
-[mediaTypes]
-[mediaTypes."my/custom-mediatype"]
-suffix = "txt"
-
-To:
-
-[mediaTypes]
-[mediaTypes."my/custom-mediatype"]
-suffixes = ["txt"]
-
-Note that you can still get the Media Type's suffix from a template: {{ $mediaType.Suffix }}. But this will now map to the MIME type filename.
-`)
}
import (
"bufio"
+ "errors"
"fmt"
"os"
"path/filepath"
"github.com/rogpeppe/go-internal/module"
- "errors"
-
"github.com/gohugoio/hugo/config"
"github.com/spf13/afero"
)
const vendorModulesFilename = "modules.txt"
-// IsNotExist returns whether an error means that a module could not be found.
-func IsNotExist(err error) bool {
- return errors.Is(err, os.ErrNotExist)
-}
-
func (h *Client) Collect() (ModulesConfig, error) {
mc, coll := h.collect(true)
if coll.err != nil {
if len(mod.ConfigFilenames()) > 0 {
return true
}
-
}
return false
}
}
func (c *collector) add(owner *moduleAdapter, moduleImport Import) (*moduleAdapter, error) {
-
var (
mod *goModule
moduleDir string
} else {
continue
}
-
}
// Verify that target points to one of the predefined component dirs
return img, nil
}
-func (i *imageResource) decodeImageConfig(action, spec string) (images.ImageConfig, error) {
- options := strings.Fields(spec)
- conf, err := images.DecodeImageConfig(action, options, i.Proc.Cfg, i.Format)
- if err != nil {
- return conf, err
- }
-
- return conf, nil
-}
-
type giphy struct {
image.Image
gif *gif.GIF
// ErrProvider provides an Err.
type ErrProvider interface {
-
// Err returns an error if this resource is in an error state.
// This will currently only be set for resources obtained from resources.GetRemote.
Err() ResourceError
func NewResourceTypesProvider(mediaType media.Type, resourceType string) ResourceTypesProvider {
return resourceTypesHolder{mediaType: mediaType, resourceType: resourceType}
}
-
-type languageHolder struct {
- lang *langs.Language
-}
-
-func (l languageHolder) Language() *langs.Language {
- return l.lang
-}
-
-func NewLanguageProvider(lang *langs.Language) LanguageProvider {
- return languageHolder{lang: lang}
-}
}
return m
-
}
func toHTTPError(err error, res *http.Response, readBody bool) *HTTPError {
if res.StatusCode != http.StatusNotFound {
if res.StatusCode < 200 || res.StatusCode > 299 {
return nil, temporaryHTTPStatusCodes[res.StatusCode], toHTTPError(fmt.Errorf("failed to fetch remote resource: %s", http.StatusText(res.StatusCode)), res, !isHeadMethod)
-
}
}
}
return b, false, nil
-
}()
-
if err != nil {
if retry {
if start.IsZero() {
return hugio.ToReadCloser(bytes.NewReader(b)), nil
}
-
})
if err != nil {
return nil, err
}
}
-func hasHeaderValue(m http.Header, key, value string) bool {
- var s []string
- var ok bool
-
- if s, ok = m[key]; !ok {
- return false
- }
-
- for _, v := range s {
- if v == value {
- return true
- }
- }
- return false
-}
-
func hasHeaderKey(m http.Header, key string) bool {
_, ok := m[key]
return ok
TextTmpl() TemplateParseFinder
}
-// WithInfo wraps the info in a template.
-func WithInfo(templ Template, info Info) Template {
- if manager, ok := info.(InfoManager); ok {
- return &templateInfoManager{
- Template: templ,
- InfoManager: manager,
- }
- }
-
- return &templateInfo{
- Template: templ,
- Info: info,
- }
-}
-
var baseOfRe = regexp.MustCompile("template: (.*?):")
func extractBaseOf(err string) string {
IsNode() bool
}
-func GetHasLockFromContext(ctx context.Context) bool {
- if v := ctx.Value(texttemplate.HasLockContextKey); v != nil {
- return v.(bool)
- }
- return false
-}
-
-func SetHasLockInContext(ctx context.Context, hasLock bool) context.Context {
- return context.WithValue(ctx, texttemplate.HasLockContextKey, hasLock)
-}
-
func GetCallbackFunctionFromContext(ctx context.Context) any {
return ctx.Value(texttemplate.CallbackContextKey)
}
identity.Manager
}
-type defaultInfo struct {
- identity.Manager
- parseInfo ParseInfo
-}
-
-func NewInfo(id identity.Manager, parseInfo ParseInfo) Info {
- return &defaultInfo{
- Manager: id,
- parseInfo: parseInfo,
- }
-}
-
-func (info *defaultInfo) ParseInfo() ParseInfo {
- return info.parseInfo
-}
-
type ParseInfo struct {
// Set for shortcode templates with any {{ .Inner }}
IsInner bool
--- /dev/null
+deadcode -test ./... | grep -v go_templ
\ No newline at end of file