-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace absoluteUrl filter with canonicalUrl filter
- Loading branch information
1 parent
e160cf6
commit db14db4
Showing
9 changed files
with
61 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const path = require('node:path') | ||
|
||
/** | ||
* Get canonical site URL with resolved path | ||
* @param {string} string - Path to resolve | ||
* @returns {string} Canonical site URL with resolved path | ||
*/ | ||
module.exports = function (string) { | ||
const { url } = this.ctx.options | ||
|
||
// If plugin options do not provide a site URL, return the path | ||
if (!URL.canParse(url)) { | ||
return string | ||
} | ||
|
||
const siteUrl = new URL(url) | ||
|
||
// If incoming string is a URL, return that if it’s an external URL | ||
if (URL.canParse(string)) { | ||
const incomingUrl = new URL(string) | ||
|
||
if (siteUrl.hostname !== incomingUrl.hostname) { | ||
return string | ||
} | ||
} | ||
|
||
// String is a path, so append it to any path on site URL | ||
siteUrl.pathname = path.join(siteUrl.pathname, string) | ||
|
||
return siteUrl.href | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const assert = require('assert/strict') | ||
Check failure on line 1 in test/lib/filters/canonical-url.js
|
||
const { describe, it } = require('node:test') | ||
Check failure on line 2 in test/lib/filters/canonical-url.js
|
||
const canonicalURL = require('../../../lib/filters/canonical-url.js') | ||
Check failure on line 3 in test/lib/filters/canonical-url.js
|
||
|
||
// TODO: Work out how to pass Nunjucks `this` context to filter for testing | ||
describe('canonicalURL filter', () => { | ||
// it('Returns path if no site options', () => { | ||
// }) | ||
// it('Returns URL if hostname does not match that of site', () => { | ||
// }) | ||
// it('Returns URL with path added', () => { | ||
// }) | ||
}) |