1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | const url_1 = require("url");
|
6 | const encode_url_1 = __importDefault(require("./encode_url"));
|
7 | const pretty_urls_1 = __importDefault(require("./pretty_urls"));
|
8 | const cache_1 = __importDefault(require("./cache"));
|
9 | const cache = new cache_1.default();
|
10 | function fullUrlForHelper(path = '/') {
|
11 | const { config } = this;
|
12 | const prettyUrlsOptions = Object.assign({
|
13 | trailing_index: true,
|
14 | trailing_html: true
|
15 | }, config.pretty_urls);
|
16 |
|
17 | return cache.apply(`${config.url}-${prettyUrlsOptions.trailing_index}-${prettyUrlsOptions.trailing_html}-${path}`, () => {
|
18 | if (/^(\/\/|http(s)?:)/.test(path))
|
19 | return path;
|
20 | const sitehost = (0, url_1.parse)(config.url).hostname || config.url;
|
21 | const data = new URL(path, `http://${sitehost}`);
|
22 |
|
23 | if (data.hostname !== sitehost || data.origin === 'null')
|
24 | return path;
|
25 | path = (0, encode_url_1.default)(config.url + `/${path}`.replace(/\/{2,}/g, '/'));
|
26 | path = (0, pretty_urls_1.default)(path, prettyUrlsOptions);
|
27 | return path;
|
28 | });
|
29 | }
|
30 | module.exports = fullUrlForHelper;
|
31 |
|
\ | No newline at end of file |