UNPKG

1.45 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5const url_1 = require("url");
6const encode_url_1 = __importDefault(require("./encode_url"));
7const pretty_urls_1 = __importDefault(require("./pretty_urls"));
8const cache_1 = __importDefault(require("./cache"));
9const cache = new cache_1.default();
10function fullUrlForHelper(path = '/') {
11 const { config } = this;
12 const prettyUrlsOptions = Object.assign({
13 trailing_index: true,
14 trailing_html: true
15 }, config.pretty_urls);
16 // cacheId is designed to works across different hexo.config & options
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 // Exit if input is an external link or a data url
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}
30module.exports = fullUrlForHelper;
31//# sourceMappingURL=full_url_for.js.map
\No newline at end of file