| 1 |
// Copyright 2019 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 page contains the core interfaces and types for the Page resource, |
| 15 |
// a core component in Hugo. |
| 16 |
package page |
| 17 |
|
| 18 |
import ( |
| 19 |
"bytes" |
| 20 |
"context" |
| 21 |
"html/template" |
| 22 |
"time" |
| 23 |
|
| 24 |
"github.com/gohugoio/hugo/hugolib/roles" |
| 25 |
"github.com/gohugoio/hugo/markup/converter" |
| 26 |
"github.com/gohugoio/hugo/markup/tableofcontents" |
| 27 |
|
| 28 |
"github.com/gohugoio/hugo/hugofs" |
| 29 |
|
| 30 |
"github.com/gohugoio/hugo/navigation" |
| 31 |
|
| 32 |
"github.com/gohugoio/hugo/common/hmaps" |
| 33 |
"github.com/gohugoio/hugo/common/hstore" |
| 34 |
"github.com/gohugoio/hugo/common/paths" |
| 35 |
"github.com/gohugoio/hugo/source" |
| 36 |
|
| 37 |
"github.com/gohugoio/hugo/config" |
| 38 |
"github.com/gohugoio/hugo/langs" |
| 39 |
"github.com/gohugoio/hugo/media" |
| 40 |
"github.com/gohugoio/hugo/related" |
| 41 |
"github.com/gohugoio/hugo/resources/resource" |
| 42 |
) |
| 43 |
|
| 44 |
var ( |
| 45 |
NopPage Page = new(nopPage) |
| 46 |
NopContentRenderer ContentRenderer = new(nopContentRenderer) |
| 47 |
NopMarkup Markup = new(nopMarkup) |
| 48 |
NopContent Content = new(nopContent) |
| 49 |
NopCPageContentRenderer = struct { |
| 50 |
OutputFormatPageContentProvider |
| 51 |
ContentRenderer |
| 52 |
}{ |
| 53 |
NopPage, |
| 54 |
NopContentRenderer, |
| 55 |
} |
| 56 |
NilPage *nopPage |
| 57 |
) |
| 58 |
|
| 59 |
// PageNop implements Page, but does nothing. |
| 60 |
type nopPage int |
| 61 |
|
| 62 |
func (p *nopPage) Aliases() []string { |
| 63 |
return nil |
| 64 |
} |
| 65 |
|
| 66 |
func (p *nopPage) Sitemap() config.SitemapConfig { |
| 67 |
return config.SitemapConfig{} |
| 68 |
} |
| 69 |
|
| 70 |
func (p *nopPage) Layout() string { |
| 71 |
return "" |
| 72 |
} |
| 73 |
|
| 74 |
func (p *nopPage) AllTranslations() Pages { |
| 75 |
return nil |
| 76 |
} |
| 77 |
|
| 78 |
func (p *nopPage) LanguagePrefix() string { |
| 79 |
return "" |
| 80 |
} |
| 81 |
|
| 82 |
func (p *nopPage) AlternativeOutputFormats() OutputFormats { |
| 83 |
return nil |
| 84 |
} |
| 85 |
|
| 86 |
func (p *nopPage) BaseFileName() string { |
| 87 |
return "" |
| 88 |
} |
| 89 |
|
| 90 |
func (p *nopPage) BundleType() string { |
| 91 |
return "" |
| 92 |
} |
| 93 |
|
| 94 |
func (p *nopPage) Markup(...any) Markup { |
| 95 |
return NopMarkup |
| 96 |
} |
| 97 |
|
| 98 |
func (p *nopPage) Content(context.Context) (any, error) { |
| 99 |
return "", nil |
| 100 |
} |
| 101 |
|
| 102 |
func (p *nopPage) ContentWithoutSummary(ctx context.Context) (template.HTML, error) { |
| 103 |
return "", nil |
| 104 |
} |
| 105 |
|
| 106 |
func (p *nopPage) ContentBaseName() string { |
| 107 |
return "" |
| 108 |
} |
| 109 |
|
| 110 |
func (p *nopPage) CurrentSection() Page { |
| 111 |
return nil |
| 112 |
} |
| 113 |
|
| 114 |
func (p *nopPage) Data() any { |
| 115 |
return nil |
| 116 |
} |
| 117 |
|
| 118 |
func (p *nopPage) Date() (t time.Time) { |
| 119 |
return |
| 120 |
} |
| 121 |
|
| 122 |
func (p *nopPage) Description() string { |
| 123 |
return "" |
| 124 |
} |
| 125 |
|
| 126 |
func (p *nopPage) RefFrom(argsm map[string]any, source any) (string, error) { |
| 127 |
return "", nil |
| 128 |
} |
| 129 |
|
| 130 |
func (p *nopPage) RelRefFrom(argsm map[string]any, source any) (string, error) { |
| 131 |
return "", nil |
| 132 |
} |
| 133 |
|
| 134 |
func (p *nopPage) Dir() string { |
| 135 |
return "" |
| 136 |
} |
| 137 |
|
| 138 |
func (p *nopPage) Draft() bool { |
| 139 |
return false |
| 140 |
} |
| 141 |
|
| 142 |
func (p *nopPage) Eq(other any) bool { |
| 143 |
return p == other |
| 144 |
} |
| 145 |
|
| 146 |
func (p *nopPage) ExpiryDate() (t time.Time) { |
| 147 |
return |
| 148 |
} |
| 149 |
|
| 150 |
func (p *nopPage) File() *source.File { |
| 151 |
return nil |
| 152 |
} |
| 153 |
|
| 154 |
func (p *nopPage) FileInfo() hugofs.FileMetaInfo { |
| 155 |
return nil |
| 156 |
} |
| 157 |
|
| 158 |
func (p *nopPage) Filename() string { |
| 159 |
return "" |
| 160 |
} |
| 161 |
|
| 162 |
func (p *nopPage) FirstSection() Page { |
| 163 |
return nil |
| 164 |
} |
| 165 |
|
| 166 |
func (p *nopPage) FuzzyWordCount(context.Context) int { |
| 167 |
return 0 |
| 168 |
} |
| 169 |
|
| 170 |
func (p *nopPage) GetPage(ref string) (Page, error) { |
| 171 |
return nil, nil |
| 172 |
} |
| 173 |
|
| 174 |
func (p *nopPage) GetParam(key string) any { |
| 175 |
return nil |
| 176 |
} |
| 177 |
|
| 178 |
func (p *nopPage) GetTerms(taxonomy string) Pages { |
| 179 |
return nil |
| 180 |
} |
| 181 |
|
| 182 |
func (p *nopPage) GitInfo() *source.GitInfo { |
| 183 |
return nil |
| 184 |
} |
| 185 |
|
| 186 |
func (p *nopPage) CodeOwners() []string { |
| 187 |
return nil |
| 188 |
} |
| 189 |
|
| 190 |
func (p *nopPage) HasMenuCurrent(menuID string, me *navigation.MenuEntry) bool { |
| 191 |
return false |
| 192 |
} |
| 193 |
|
| 194 |
func (p *nopPage) HasShortcode(name string) bool { |
| 195 |
return false |
| 196 |
} |
| 197 |
|
| 198 |
func (p *nopPage) Hugo() (h HugoInfo) { |
| 199 |
return |
| 200 |
} |
| 201 |
|
| 202 |
func (p *nopPage) InSection(other any) bool { |
| 203 |
return false |
| 204 |
} |
| 205 |
|
| 206 |
func (p *nopPage) IsAncestor(other any) bool { |
| 207 |
return false |
| 208 |
} |
| 209 |
|
| 210 |
func (p *nopPage) IsDescendant(other any) bool { |
| 211 |
return false |
| 212 |
} |
| 213 |
|
| 214 |
func (p *nopPage) IsDraft() bool { |
| 215 |
return false |
| 216 |
} |
| 217 |
|
| 218 |
func (p *nopPage) IsHome() bool { |
| 219 |
return false |
| 220 |
} |
| 221 |
|
| 222 |
func (p *nopPage) IsMenuCurrent(menuID string, inme *navigation.MenuEntry) bool { |
| 223 |
return false |
| 224 |
} |
| 225 |
|
| 226 |
func (p *nopPage) IsNode() bool { |
| 227 |
return false |
| 228 |
} |
| 229 |
|
| 230 |
func (p *nopPage) IsBranch() bool { |
| 231 |
return false |
| 232 |
} |
| 233 |
|
| 234 |
func (p *nopPage) IsPage() bool { |
| 235 |
return false |
| 236 |
} |
| 237 |
|
| 238 |
func (p *nopPage) IsSection() bool { |
| 239 |
return false |
| 240 |
} |
| 241 |
|
| 242 |
func (p *nopPage) IsTranslated() bool { |
| 243 |
return false |
| 244 |
} |
| 245 |
|
| 246 |
func (p *nopPage) Keywords() []string { |
| 247 |
return nil |
| 248 |
} |
| 249 |
|
| 250 |
func (p *nopPage) Kind() string { |
| 251 |
return "" |
| 252 |
} |
| 253 |
|
| 254 |
func (p *nopPage) Lang() string { |
| 255 |
return "" |
| 256 |
} |
| 257 |
|
| 258 |
func (p *nopPage) Language() *langs.Language { |
| 259 |
return nil |
| 260 |
} |
| 261 |
|
| 262 |
func (p *nopPage) Role() roles.Role { |
| 263 |
return nil |
| 264 |
} |
| 265 |
|
| 266 |
func (p *nopPage) Lastmod() (t time.Time) { |
| 267 |
return |
| 268 |
} |
| 269 |
|
| 270 |
func (p *nopPage) Len(context.Context) int { |
| 271 |
return 0 |
| 272 |
} |
| 273 |
|
| 274 |
func (p *nopPage) LinkTitle() string { |
| 275 |
return "" |
| 276 |
} |
| 277 |
|
| 278 |
func (p *nopPage) LogicalName() string { |
| 279 |
return "" |
| 280 |
} |
| 281 |
|
| 282 |
func (p *nopPage) MediaType() (m media.Type) { |
| 283 |
return |
| 284 |
} |
| 285 |
|
| 286 |
func (p *nopPage) Menus() (m navigation.PageMenus) { |
| 287 |
return |
| 288 |
} |
| 289 |
|
| 290 |
func (p *nopPage) Name() string { |
| 291 |
return "" |
| 292 |
} |
| 293 |
|
| 294 |
func (p *nopPage) Next() Page { |
| 295 |
return nil |
| 296 |
} |
| 297 |
|
| 298 |
func (p *nopPage) OutputFormats() OutputFormats { |
| 299 |
return nil |
| 300 |
} |
| 301 |
|
| 302 |
func (p *nopPage) Pages() Pages { |
| 303 |
return nil |
| 304 |
} |
| 305 |
|
| 306 |
func (p *nopPage) RegularPages() Pages { |
| 307 |
return nil |
| 308 |
} |
| 309 |
|
| 310 |
func (p *nopPage) RegularPagesRecursive() Pages { |
| 311 |
return nil |
| 312 |
} |
| 313 |
|
| 314 |
func (p *nopPage) Paginate(seq any, options ...any) (*Pager, error) { |
| 315 |
return nil, nil |
| 316 |
} |
| 317 |
|
| 318 |
func (p *nopPage) Paginator(options ...any) (*Pager, error) { |
| 319 |
return nil, nil |
| 320 |
} |
| 321 |
|
| 322 |
func (p *nopPage) Param(key any) (any, error) { |
| 323 |
return nil, nil |
| 324 |
} |
| 325 |
|
| 326 |
func (p *nopPage) Params() hmaps.Params { |
| 327 |
return nil |
| 328 |
} |
| 329 |
|
| 330 |
func (p *nopPage) Page() Page { |
| 331 |
return p |
| 332 |
} |
| 333 |
|
| 334 |
func (p *nopPage) Parent() Page { |
| 335 |
return nil |
| 336 |
} |
| 337 |
|
| 338 |
func (p *nopPage) Ancestors() Pages { |
| 339 |
return nil |
| 340 |
} |
| 341 |
|
| 342 |
func (p *nopPage) Path() string { |
| 343 |
return "" |
| 344 |
} |
| 345 |
|
| 346 |
func (p *nopPage) PathInfo() *paths.Path { |
| 347 |
return nil |
| 348 |
} |
| 349 |
|
| 350 |
func (p *nopPage) Permalink() string { |
| 351 |
return "" |
| 352 |
} |
| 353 |
|
| 354 |
func (p *nopPage) Plain(context.Context) string { |
| 355 |
return "" |
| 356 |
} |
| 357 |
|
| 358 |
func (p *nopPage) PlainWords(context.Context) []string { |
| 359 |
return nil |
| 360 |
} |
| 361 |
|
| 362 |
func (p *nopPage) Prev() Page { |
| 363 |
return nil |
| 364 |
} |
| 365 |
|
| 366 |
func (p *nopPage) PublishDate() (t time.Time) { |
| 367 |
return |
| 368 |
} |
| 369 |
|
| 370 |
func (p *nopPage) PrevInSection() Page { |
| 371 |
return nil |
| 372 |
} |
| 373 |
|
| 374 |
func (p *nopPage) NextInSection() Page { |
| 375 |
return nil |
| 376 |
} |
| 377 |
|
| 378 |
func (p *nopPage) RawContent() string { |
| 379 |
return "" |
| 380 |
} |
| 381 |
|
| 382 |
func (p *nopPage) RenderShortcodes(ctx context.Context) (template.HTML, error) { |
| 383 |
return "", nil |
| 384 |
} |
| 385 |
|
| 386 |
func (p *nopPage) ReadingTime(context.Context) int { |
| 387 |
return 0 |
| 388 |
} |
| 389 |
|
| 390 |
func (p *nopPage) Ref(argsm map[string]any) (string, error) { |
| 391 |
return "", nil |
| 392 |
} |
| 393 |
|
| 394 |
func (p *nopPage) RelPermalink() string { |
| 395 |
return "" |
| 396 |
} |
| 397 |
|
| 398 |
func (p *nopPage) RelRef(argsm map[string]any) (string, error) { |
| 399 |
return "", nil |
| 400 |
} |
| 401 |
|
| 402 |
func (p *nopPage) Render(ctx context.Context, args ...any) (template.HTML, error) { |
| 403 |
return "", nil |
| 404 |
} |
| 405 |
|
| 406 |
func (p *nopPage) RenderString(ctx context.Context, args ...any) (template.HTML, error) { |
| 407 |
return "", nil |
| 408 |
} |
| 409 |
|
| 410 |
func (p *nopPage) ResourceType() string { |
| 411 |
return "" |
| 412 |
} |
| 413 |
|
| 414 |
func (p *nopPage) Resources() resource.Resources { |
| 415 |
return nil |
| 416 |
} |
| 417 |
|
| 418 |
func (p *nopPage) Scratch() *hstore.Scratch { |
| 419 |
return nil |
| 420 |
} |
| 421 |
|
| 422 |
func (p *nopPage) Store() *hstore.Scratch { |
| 423 |
return nil |
| 424 |
} |
| 425 |
|
| 426 |
func (p *nopPage) RelatedKeywords(cfg related.IndexConfig) ([]string, error) { |
| 427 |
return nil, nil |
| 428 |
} |
| 429 |
|
| 430 |
func (p *nopPage) Section() string { |
| 431 |
return "" |
| 432 |
} |
| 433 |
|
| 434 |
func (p *nopPage) Sections() Pages { |
| 435 |
return nil |
| 436 |
} |
| 437 |
|
| 438 |
func (p *nopPage) SectionsEntries() []string { |
| 439 |
return nil |
| 440 |
} |
| 441 |
|
| 442 |
func (p *nopPage) SectionsPath() string { |
| 443 |
return "" |
| 444 |
} |
| 445 |
|
| 446 |
func (p *nopPage) Site() Site { |
| 447 |
return nil |
| 448 |
} |
| 449 |
|
| 450 |
func (p *nopPage) Sites() Sites { |
| 451 |
return nil |
| 452 |
} |
| 453 |
|
| 454 |
func (p *nopPage) Slug() string { |
| 455 |
return "" |
| 456 |
} |
| 457 |
|
| 458 |
func (p *nopPage) String() string { |
| 459 |
return "nopPage" |
| 460 |
} |
| 461 |
|
| 462 |
func (p *nopPage) Summary(context.Context) template.HTML { |
| 463 |
return "" |
| 464 |
} |
| 465 |
|
| 466 |
func (p *nopPage) TableOfContents(context.Context) template.HTML { |
| 467 |
return "" |
| 468 |
} |
| 469 |
|
| 470 |
func (p *nopPage) Title() string { |
| 471 |
return "" |
| 472 |
} |
| 473 |
|
| 474 |
func (p *nopPage) TranslationBaseName() string { |
| 475 |
return "" |
| 476 |
} |
| 477 |
|
| 478 |
func (p *nopPage) TranslationKey() string { |
| 479 |
return "" |
| 480 |
} |
| 481 |
|
| 482 |
func (p *nopPage) Translations() Pages { |
| 483 |
return nil |
| 484 |
} |
| 485 |
|
| 486 |
func (p *nopPage) Truncated(context.Context) bool { |
| 487 |
return false |
| 488 |
} |
| 489 |
|
| 490 |
func (p *nopPage) Type() string { |
| 491 |
return "" |
| 492 |
} |
| 493 |
|
| 494 |
func (p *nopPage) URL() string { |
| 495 |
return "" |
| 496 |
} |
| 497 |
|
| 498 |
func (p *nopPage) UniqueID() string { |
| 499 |
return "" |
| 500 |
} |
| 501 |
|
| 502 |
func (p *nopPage) Weight() int { |
| 503 |
return 0 |
| 504 |
} |
| 505 |
|
| 506 |
func (p *nopPage) WordCount(context.Context) int { |
| 507 |
return 0 |
| 508 |
} |
| 509 |
|
| 510 |
func (p *nopPage) Fragments(context.Context) *tableofcontents.Fragments { |
| 511 |
return nil |
| 512 |
} |
| 513 |
|
| 514 |
func (p *nopPage) HeadingsFiltered(context.Context) tableofcontents.Headings { |
| 515 |
return nil |
| 516 |
} |
| 517 |
|
| 518 |
type nopContentRenderer int |
| 519 |
|
| 520 |
func (r *nopContentRenderer) ParseAndRenderContent(ctx context.Context, content []byte, renderTOC bool) (converter.ResultRender, error) { |
| 521 |
b := &bytes.Buffer{} |
| 522 |
return b, nil |
| 523 |
} |
| 524 |
|
| 525 |
func (r *nopContentRenderer) ParseContent(ctx context.Context, content []byte) (converter.ResultParse, bool, error) { |
| 526 |
return nil, false, nil |
| 527 |
} |
| 528 |
|
| 529 |
func (r *nopContentRenderer) RenderContent(ctx context.Context, content []byte, sourceInfo, doc any) (converter.ResultRender, bool, error) { |
| 530 |
return nil, false, nil |
| 531 |
} |
| 532 |
|
| 533 |
type ( |
| 534 |
nopMarkup int |
| 535 |
nopContent int |
| 536 |
) |
| 537 |
|
| 538 |
var ( |
| 539 |
_ Markup = (*nopMarkup)(nil) |
| 540 |
_ Content = (*nopContent)(nil) |
| 541 |
) |
| 542 |
|
| 543 |
func (c *nopMarkup) Render(context.Context) (Content, error) { |
| 544 |
return NopContent, nil |
| 545 |
} |
| 546 |
|
| 547 |
func (c *nopMarkup) RenderString(ctx context.Context, args ...any) (template.HTML, error) { |
| 548 |
return "", nil |
| 549 |
} |
| 550 |
|
| 551 |
func (c *nopMarkup) RenderShortcodes(context.Context) (template.HTML, error) { |
| 552 |
return "", nil |
| 553 |
} |
| 554 |
|
| 555 |
func (c *nopContent) Plain(context.Context) string { |
| 556 |
return "" |
| 557 |
} |
| 558 |
|
| 559 |
func (c *nopContent) PlainWords(context.Context) []string { |
| 560 |
return nil |
| 561 |
} |
| 562 |
|
| 563 |
func (c *nopContent) WordCount(context.Context) int { |
| 564 |
return 0 |
| 565 |
} |
| 566 |
|
| 567 |
func (c *nopContent) FuzzyWordCount(context.Context) int { |
| 568 |
return 0 |
| 569 |
} |
| 570 |
|
| 571 |
func (c *nopContent) ReadingTime(context.Context) int { |
| 572 |
return 0 |
| 573 |
} |
| 574 |
|
| 575 |
func (c *nopContent) Len(context.Context) int { |
| 576 |
return 0 |
| 577 |
} |
| 578 |
|
| 579 |
func (c *nopContent) Content(context.Context) (template.HTML, error) { |
| 580 |
return "", nil |
| 581 |
} |
| 582 |
|
| 583 |
func (c *nopContent) ContentWithoutSummary(context.Context) (template.HTML, error) { |
| 584 |
return "", nil |
| 585 |
} |
| 586 |
|
| 587 |
func (c *nopMarkup) Fragments(context.Context) *tableofcontents.Fragments { |
| 588 |
return nil |
| 589 |
} |
| 590 |
|
| 591 |
func (c *nopMarkup) FragmentsHTML(context.Context) template.HTML { |
| 592 |
return "" |
| 593 |
} |
| 594 |
|
| 595 |
func (c *nopContent) Summary(context.Context) (Summary, error) { |
| 596 |
return Summary{}, nil |
| 597 |
} |