Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/build-pages/page-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { resolveVars, resolvePostVars } from './resolve-vars.js'
import { pageBuilders } from './page-builders/index.js'
import { fsPathToUrlPath } from './page-builders/fs-path-to-url.js'
// @ts-expect-error
import pretty from 'pretty'

Expand Down Expand Up @@ -141,6 +142,7 @@ export class PageData {
const { globalVars, globalDataVars, pageVars, builderVars } = this
// @ts-ignore
return {
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of this?

pageUrl: this.#computePageUrl(),
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a method?

...globalVars,
...globalDataVars,
...pageVars,
Expand All @@ -156,6 +158,19 @@ export class PageData {
return this.workerFiles
}

/**
* Derive the canonical URL path for this page from its filesystem path and output name.
* Index pages get a trailing-slash URL; other outputs include the filename.
* @return {string}
*/
#computePageUrl () {
const { path, outputName } = this.pageInfo
if (outputName === 'index.html') {
return path ? fsPathToUrlPath(path) + '/' : '/'
}
return path ? fsPathToUrlPath(path) + '/' + outputName : '/' + outputName
Comment thread
bcomnes marked this conversation as resolved.
Outdated
}

/**
* [init description]
* @param {object} params - Parameters required to initialize
Expand Down