mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-25 22:00:58 +02:00
Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code. Also, * Lower case the default output format names; this is in line with the custom ones (map keys) and how it's treated all the places. This avoids doing `stringds.EqualFold` everywhere. Closes #10896 Closes #10620
This commit is contained in:
@@ -53,32 +53,15 @@ var (
|
||||
// DefaultConfig is the default related config.
|
||||
DefaultConfig = Config{
|
||||
Threshold: 80,
|
||||
Indices: IndexConfigs{
|
||||
Indices: IndicesConfig{
|
||||
IndexConfig{Name: "keywords", Weight: 100, Type: TypeBasic},
|
||||
IndexConfig{Name: "date", Weight: 10, Type: TypeBasic},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
/*
|
||||
Config is the top level configuration element used to configure how to retrieve
|
||||
related content in Hugo.
|
||||
|
||||
An example site config.toml:
|
||||
|
||||
[related]
|
||||
threshold = 1
|
||||
[[related.indices]]
|
||||
name = "keywords"
|
||||
weight = 200
|
||||
[[related.indices]]
|
||||
name = "tags"
|
||||
weight = 100
|
||||
[[related.indices]]
|
||||
name = "date"
|
||||
weight = 1
|
||||
pattern = "2006"
|
||||
*/
|
||||
// Config is the top level configuration element used to configure how to retrieve
|
||||
// related content in Hugo.
|
||||
type Config struct {
|
||||
// Only include matches >= threshold, a normalized rank between 0 and 100.
|
||||
Threshold int
|
||||
@@ -90,7 +73,7 @@ type Config struct {
|
||||
// May get better results, but at a slight performance cost.
|
||||
ToLower bool
|
||||
|
||||
Indices IndexConfigs
|
||||
Indices IndicesConfig
|
||||
}
|
||||
|
||||
// Add adds a given index.
|
||||
@@ -110,8 +93,8 @@ func (c *Config) HasType(s string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IndexConfigs holds a set of index configurations.
|
||||
type IndexConfigs []IndexConfig
|
||||
// IndicesConfig holds a set of index configurations.
|
||||
type IndicesConfig []IndexConfig
|
||||
|
||||
// IndexConfig configures an index.
|
||||
type IndexConfig struct {
|
||||
@@ -366,13 +349,13 @@ func (idx *InvertedIndex) Search(ctx context.Context, opts SearchOpts) ([]Docume
|
||||
|
||||
var (
|
||||
queryElements []queryElement
|
||||
configs IndexConfigs
|
||||
configs IndicesConfig
|
||||
)
|
||||
|
||||
if len(opts.Indices) == 0 {
|
||||
configs = idx.cfg.Indices
|
||||
} else {
|
||||
configs = make(IndexConfigs, len(opts.Indices))
|
||||
configs = make(IndicesConfig, len(opts.Indices))
|
||||
for i, indexName := range opts.Indices {
|
||||
cfg, found := idx.getIndexCfg(indexName)
|
||||
if !found {
|
||||
@@ -396,12 +379,14 @@ func (idx *InvertedIndex) Search(ctx context.Context, opts SearchOpts) ([]Docume
|
||||
keywords = append(keywords, FragmentKeyword(fragment))
|
||||
}
|
||||
if opts.Document != nil {
|
||||
|
||||
if fp, ok := opts.Document.(FragmentProvider); ok {
|
||||
for _, fragment := range fp.Fragments(ctx).Identifiers {
|
||||
keywords = append(keywords, FragmentKeyword(fragment))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
queryElements = append(queryElements, newQueryElement(cfg.Name, keywords...))
|
||||
}
|
||||
@@ -553,6 +538,7 @@ func (idx *InvertedIndex) searchDate(ctx context.Context, self Document, upperDa
|
||||
|
||||
for i, m := range matches {
|
||||
result[i] = m.Doc
|
||||
|
||||
if len(fragmentsFilter) > 0 {
|
||||
if dp, ok := result[i].(FragmentProvider); ok {
|
||||
result[i] = dp.ApplyFilterToHeadings(ctx, func(h *tableofcontents.Heading) bool {
|
||||
|
Reference in New Issue
Block a user