Debian Codegraph @

tpl/tplimpl/legacy.go

raw
1 // Copyright 2025 The Hugo Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package tplimpl
15
16 import (
17 "github.com/gohugoio/hugo/hugofs"
18 "github.com/gohugoio/hugo/resources/kinds"
19 )
20
21 type layoutLegacyMapping struct {
22 sourcePath string
23 target layoutLegacyMappingTarget
24 }
25
26 type layoutLegacyMappingTarget struct {
27 targetPath string
28 targetDesc TemplateDescriptor
29 targetCategory Category
30 }
31
32 var (
33 ltermPlural = layoutLegacyMappingTarget{
34 targetPath: "/PLURAL",
35 targetDesc: TemplateDescriptor{Kind: kinds.KindTerm},
36 targetCategory: CategoryLayout,
37 }
38 ltermBase = layoutLegacyMappingTarget{
39 targetPath: "",
40 targetDesc: TemplateDescriptor{Kind: kinds.KindTerm},
41 targetCategory: CategoryLayout,
42 }
43
44 ltaxPlural = layoutLegacyMappingTarget{
45 targetPath: "/PLURAL",
46 targetDesc: TemplateDescriptor{Kind: kinds.KindTaxonomy},
47 targetCategory: CategoryLayout,
48 }
49 ltaxBase = layoutLegacyMappingTarget{
50 targetPath: "",
51 targetDesc: TemplateDescriptor{Kind: kinds.KindTaxonomy},
52 targetCategory: CategoryLayout,
53 }
54
55 lsectBase = layoutLegacyMappingTarget{
56 targetPath: "",
57 targetDesc: TemplateDescriptor{Kind: kinds.KindSection},
58 targetCategory: CategoryLayout,
59 }
60 lsectTheSection = layoutLegacyMappingTarget{
61 targetPath: "/THESECTION",
62 targetDesc: TemplateDescriptor{Kind: kinds.KindSection},
63 targetCategory: CategoryLayout,
64 }
65 )
66
67 type legacyTargetPathIdentifiers struct {
68 targetPath string
69 targetCategory Category
70 kind string
71 outputFormat string
72 ext string
73 }
74
75 type legacyOrdinalMapping struct {
76 ordinal int
77 mapping layoutLegacyMappingTarget
78 }
79
80 type legacyOrdinalMappingFi struct {
81 m legacyOrdinalMapping
82 fi hugofs.FileMetaInfo
83 }
84
85 var legacyTermMappings = []layoutLegacyMapping{
86 {sourcePath: "/PLURAL/term", target: ltermPlural},
87 {sourcePath: "/PLURAL/SINGULAR", target: ltermPlural},
88 {sourcePath: "/term/term", target: ltermBase},
89 {sourcePath: "/term/SINGULAR", target: ltermPlural},
90 {sourcePath: "/term/taxonomy", target: ltermPlural},
91 {sourcePath: "/term/list", target: ltermBase},
92 {sourcePath: "/taxonomy/term", target: ltermBase},
93 {sourcePath: "/taxonomy/SINGULAR", target: ltermPlural},
94 {sourcePath: "/SINGULAR/term", target: ltermPlural},
95 {sourcePath: "/SINGULAR/SINGULAR", target: ltermPlural},
96 {sourcePath: "/_default/SINGULAR", target: ltermPlural},
97 {sourcePath: "/_default/taxonomy", target: ltermBase},
98 }
99
100 var legacyTaxonomyMappings = []layoutLegacyMapping{
101 {sourcePath: "/PLURAL/SINGULAR.terms", target: ltaxPlural},
102 {sourcePath: "/PLURAL/terms", target: ltaxPlural},
103 {sourcePath: "/PLURAL/taxonomy", target: ltaxPlural},
104 {sourcePath: "/PLURAL/list", target: ltaxPlural},
105 {sourcePath: "/SINGULAR/SINGULAR.terms", target: ltaxPlural},
106 {sourcePath: "/SINGULAR/terms", target: ltaxPlural},
107 {sourcePath: "/SINGULAR/taxonomy", target: ltaxPlural},
108 {sourcePath: "/SINGULAR/list", target: ltaxPlural},
109 {sourcePath: "/taxonomy/SINGULAR.terms", target: ltaxPlural},
110 {sourcePath: "/taxonomy/terms", target: ltaxBase},
111 {sourcePath: "/taxonomy/taxonomy", target: ltaxBase},
112 {sourcePath: "/taxonomy/list", target: ltaxBase},
113 {sourcePath: "/_default/SINGULAR.terms", target: ltaxBase},
114 {sourcePath: "/_default/terms", target: ltaxBase},
115 {sourcePath: "/_default/taxonomy", target: ltaxBase},
116 }
117
118 var legacySectionMappings = []layoutLegacyMapping{
119 // E.g. /mysection/mysection.html
120 {sourcePath: "/THESECTION/THESECTION", target: lsectTheSection},
121 // E.g. /section/mysection.html
122 {sourcePath: "/SECTIONKIND/THESECTION", target: lsectTheSection},
123 // E.g. /section/section.html
124 {sourcePath: "/SECTIONKIND/SECTIONKIND", target: lsectBase},
125 // E.g. /section/list.html
126 {sourcePath: "/SECTIONKIND/list", target: lsectBase},
127 // E.g. /_default/mysection.html
128 {sourcePath: "/_default/THESECTION", target: lsectTheSection},
129 }