@tryghost/url-utils 5.0.0 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/UrlUtils.d.ts +147 -3
- package/lib/UrlUtils.js +228 -112
- package/lib/index.d.ts +2 -0
- package/lib/index.js +6 -0
- package/lib/utils/absolute-to-relative.d.ts +9 -3
- package/lib/utils/absolute-to-relative.js +14 -9
- package/lib/utils/absolute-to-transform-ready.d.ts +13 -4
- package/lib/utils/absolute-to-transform-ready.js +16 -11
- package/lib/utils/build-early-exit-match.d.ts +11 -1
- package/lib/utils/build-early-exit-match.js +4 -4
- package/lib/utils/deduplicate-double-slashes.d.ts +2 -1
- package/lib/utils/deduplicate-double-slashes.js +2 -2
- package/lib/utils/deduplicate-subdirectory.d.ts +2 -2
- package/lib/utils/deduplicate-subdirectory.js +4 -4
- package/lib/utils/html-absolute-to-relative.d.ts +3 -3
- package/lib/utils/html-absolute-to-relative.js +10 -7
- package/lib/utils/html-absolute-to-transform-ready.d.ts +3 -4
- package/lib/utils/html-absolute-to-transform-ready.js +16 -9
- package/lib/utils/html-relative-to-absolute.d.ts +3 -3
- package/lib/utils/html-relative-to-absolute.js +43 -8
- package/lib/utils/html-relative-to-transform-ready.d.ts +3 -3
- package/lib/utils/html-relative-to-transform-ready.js +51 -11
- package/lib/utils/html-to-transform-ready.d.ts +3 -3
- package/lib/utils/html-to-transform-ready.js +17 -9
- package/lib/utils/html-transform.d.ts +5 -4
- package/lib/utils/html-transform.js +25 -21
- package/lib/utils/index.d.ts +76 -0
- package/lib/utils/index.js +115 -38
- package/lib/utils/is-ssl.d.ts +2 -2
- package/lib/utils/is-ssl.js +4 -4
- package/lib/utils/lexical-absolute-to-relative.d.ts +3 -2
- package/lib/utils/lexical-absolute-to-relative.js +9 -6
- package/lib/utils/lexical-absolute-to-transform-ready.d.ts +3 -2
- package/lib/utils/lexical-absolute-to-transform-ready.js +10 -7
- package/lib/utils/lexical-relative-to-absolute.d.ts +3 -3
- package/lib/utils/lexical-relative-to-absolute.js +8 -5
- package/lib/utils/lexical-relative-to-transform-ready.d.ts +3 -3
- package/lib/utils/lexical-relative-to-transform-ready.js +8 -5
- package/lib/utils/lexical-to-transform-ready.d.ts +3 -3
- package/lib/utils/lexical-to-transform-ready.js +17 -9
- package/lib/utils/lexical-transform.d.ts +3 -2
- package/lib/utils/lexical-transform.js +22 -19
- package/lib/utils/markdown-absolute-to-relative.d.ts +3 -4
- package/lib/utils/markdown-absolute-to-relative.js +11 -8
- package/lib/utils/markdown-absolute-to-transform-ready.d.ts +3 -5
- package/lib/utils/markdown-absolute-to-transform-ready.js +17 -10
- package/lib/utils/markdown-relative-to-absolute.d.ts +3 -4
- package/lib/utils/markdown-relative-to-absolute.js +11 -8
- package/lib/utils/markdown-relative-to-transform-ready.d.ts +3 -4
- package/lib/utils/markdown-relative-to-transform-ready.js +11 -8
- package/lib/utils/markdown-to-transform-ready.d.ts +3 -3
- package/lib/utils/markdown-to-transform-ready.js +17 -9
- package/lib/utils/markdown-transform.d.ts +3 -5
- package/lib/utils/markdown-transform.js +12 -6
- package/lib/utils/mobiledoc-absolute-to-relative.d.ts +3 -2
- package/lib/utils/mobiledoc-absolute-to-relative.js +9 -6
- package/lib/utils/mobiledoc-absolute-to-transform-ready.d.ts +3 -2
- package/lib/utils/mobiledoc-absolute-to-transform-ready.js +10 -7
- package/lib/utils/mobiledoc-relative-to-absolute.d.ts +3 -3
- package/lib/utils/mobiledoc-relative-to-absolute.js +8 -5
- package/lib/utils/mobiledoc-relative-to-transform-ready.d.ts +3 -3
- package/lib/utils/mobiledoc-relative-to-transform-ready.js +8 -5
- package/lib/utils/mobiledoc-to-transform-ready.d.ts +3 -3
- package/lib/utils/mobiledoc-to-transform-ready.js +17 -9
- package/lib/utils/mobiledoc-transform.d.ts +3 -1
- package/lib/utils/mobiledoc-transform.js +5 -4
- package/lib/utils/plaintext-absolute-to-transform-ready.d.ts +5 -4
- package/lib/utils/plaintext-absolute-to-transform-ready.js +16 -11
- package/lib/utils/plaintext-relative-to-transform-ready.d.ts +3 -2
- package/lib/utils/plaintext-relative-to-transform-ready.js +15 -7
- package/lib/utils/plaintext-to-transform-ready.d.ts +5 -3
- package/lib/utils/plaintext-to-transform-ready.js +17 -9
- package/lib/utils/relative-to-absolute.d.ts +5 -3
- package/lib/utils/relative-to-absolute.js +26 -19
- package/lib/utils/relative-to-transform-ready.d.ts +8 -2
- package/lib/utils/relative-to-transform-ready.js +22 -10
- package/lib/utils/replace-permalink.d.ts +13 -2
- package/lib/utils/replace-permalink.js +44 -8
- package/lib/utils/strip-subdirectory-from-path.d.ts +1 -1
- package/lib/utils/strip-subdirectory-from-path.js +5 -5
- package/lib/utils/to-transform-ready.d.ts +5 -3
- package/lib/utils/to-transform-ready.js +17 -9
- package/lib/utils/transform-ready-to-absolute.d.ts +9 -1
- package/lib/utils/transform-ready-to-absolute.js +2 -2
- package/lib/utils/transform-ready-to-relative.d.ts +3 -1
- package/lib/utils/transform-ready-to-relative.js +4 -3
- package/lib/utils/types.d.ts +92 -0
- package/lib/utils/types.js +2 -0
- package/lib/utils/url-join.d.ts +5 -2
- package/lib/utils/url-join.js +11 -5
- package/package.json +10 -11
- package/index.js +0 -2
package/lib/UrlUtils.d.ts
CHANGED
|
@@ -1,3 +1,147 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import utils from './utils';
|
|
2
|
+
import type { HtmlTransformOptionsInput, MarkdownTransformOptionsInput, MobiledocTransformOptionsInput, LexicalTransformOptionsInput, MobiledocCardTransformer } from './utils/types';
|
|
3
|
+
import type { AbsoluteToRelativeOptionsInput } from './utils/absolute-to-relative';
|
|
4
|
+
import type { RelativeToAbsoluteOptionsInput } from './utils/relative-to-absolute';
|
|
5
|
+
import type { AbsoluteToTransformReadyOptionsInput as AbsoluteToTransformReadyOptionsInputType } from './utils/absolute-to-transform-ready';
|
|
6
|
+
import type { RelativeToTransformReadyOptionsInput as RelativeToTransformReadyOptionsInputType } from './utils/relative-to-transform-ready';
|
|
7
|
+
import type { ToTransformReadyOptions } from './utils/to-transform-ready';
|
|
8
|
+
import type { TransformReadyToAbsoluteOptionsInput } from './utils/transform-ready-to-absolute';
|
|
9
|
+
import type { TransformReadyReplacementOptionsInput as TransformReadyToRelativeOptionsInput } from './utils/types';
|
|
10
|
+
interface ExpressResponse {
|
|
11
|
+
set(headers: Record<string, string>): void;
|
|
12
|
+
redirect(status: number, url: string): void;
|
|
13
|
+
redirect(url: string): void;
|
|
14
|
+
}
|
|
15
|
+
interface UrlUtilsOptions {
|
|
16
|
+
getSubdir?: () => string;
|
|
17
|
+
getSiteUrl?: () => string;
|
|
18
|
+
getAdminUrl?: () => string;
|
|
19
|
+
baseApiPath?: string;
|
|
20
|
+
defaultApiType?: 'content' | 'admin';
|
|
21
|
+
slugs?: {
|
|
22
|
+
reserved?: string[];
|
|
23
|
+
protected?: string[];
|
|
24
|
+
} | null;
|
|
25
|
+
redirectCacheMaxAge?: number | null;
|
|
26
|
+
staticImageUrlPrefix?: string;
|
|
27
|
+
staticFilesUrlPrefix?: string;
|
|
28
|
+
staticMediaUrlPrefix?: string;
|
|
29
|
+
assetBaseUrls?: {
|
|
30
|
+
image?: string | null;
|
|
31
|
+
files?: string | null;
|
|
32
|
+
media?: string | null;
|
|
33
|
+
};
|
|
34
|
+
cardTransformers?: MobiledocCardTransformer[];
|
|
35
|
+
}
|
|
36
|
+
export default class UrlUtils {
|
|
37
|
+
private _config;
|
|
38
|
+
private _assetBaseUrls;
|
|
39
|
+
getSubdir: () => string;
|
|
40
|
+
getSiteUrl: () => string;
|
|
41
|
+
getAdminUrl: () => string;
|
|
42
|
+
/**
|
|
43
|
+
* Initialization method to pass in URL configurations
|
|
44
|
+
* @param {Object} options
|
|
45
|
+
* @param {Function} options.getSubdir
|
|
46
|
+
* @param {Function} options.getSiteUrl
|
|
47
|
+
* @param {Function} options.getAdminUrl Ghost instance admin URL
|
|
48
|
+
* @param {String} [options.baseApiPath='/ghost/api'] static prefix for serving API. Should not te passed in, unless the API is being run under custom URL
|
|
49
|
+
* @param {('content' | 'admin')} [options.defaultApiType='content'] default API type to be used
|
|
50
|
+
* @param {Object} [options.slugs] object with 2 properties reserved and protected containing arrays of special case slugs
|
|
51
|
+
* @param {Number} [options.redirectCacheMaxAge]
|
|
52
|
+
* @param {String} [options.staticImageUrlPrefix='content/images'] static prefix for serving images. Should not be passed in, unless customizing ghost instance image storage
|
|
53
|
+
* @param {String} [options.staticFilesUrlPrefix='content/files'] static prefix for serving files. Should not be passed in, unless customizing ghost instance file storage
|
|
54
|
+
* @param {String} [options.staticMediaUrlPrefix='content/media'] static prefix for serving media. Should not be passed in, unless customizing ghost instance media storage
|
|
55
|
+
* @param {object} [options.assetBaseUrls] asset CDN base URLs
|
|
56
|
+
* @param {string} [options.assetBaseUrls.image] image asset CDN base URL
|
|
57
|
+
* @param {string} [options.assetBaseUrls.files] files asset CDN base URL
|
|
58
|
+
* @param {string} [options.assetBaseUrls.media] media asset CDN base URL
|
|
59
|
+
*/
|
|
60
|
+
constructor(options?: UrlUtilsOptions);
|
|
61
|
+
private _assetOptionDefaults;
|
|
62
|
+
private _buildAssetOptions;
|
|
63
|
+
getProtectedSlugs(): string[];
|
|
64
|
+
/** urlJoin
|
|
65
|
+
* Returns a URL/path for internal use in Ghost.
|
|
66
|
+
* @param {string} arguments takes arguments and concats those to a valid path/URL.
|
|
67
|
+
* @return {string} URL concatinated URL/path of arguments.
|
|
68
|
+
*/
|
|
69
|
+
urlJoin(...parts: string[]): string;
|
|
70
|
+
createUrl(urlPath?: string, absolute?: boolean, trailingSlash?: boolean): string;
|
|
71
|
+
urlFor(context: string | {
|
|
72
|
+
relativeUrl: string;
|
|
73
|
+
} | {
|
|
74
|
+
image?: string;
|
|
75
|
+
} | {
|
|
76
|
+
nav?: {
|
|
77
|
+
url: string;
|
|
78
|
+
};
|
|
79
|
+
}, data?: Record<string, unknown> | boolean | {
|
|
80
|
+
trailingSlash?: boolean;
|
|
81
|
+
type?: 'admin' | 'content';
|
|
82
|
+
} | null, absolute?: boolean): string;
|
|
83
|
+
redirect301(res: ExpressResponse, redirectUrl: string): void;
|
|
84
|
+
redirectToAdmin(status: number, res: ExpressResponse, adminPath: string): void;
|
|
85
|
+
absoluteToRelative(url: string, options?: AbsoluteToRelativeOptionsInput): string;
|
|
86
|
+
relativeToAbsolute(url: string, options?: RelativeToAbsoluteOptionsInput): string;
|
|
87
|
+
toTransformReady(url: string, itemPath: string | null | ToTransformReadyOptions, options?: ToTransformReadyOptions): string;
|
|
88
|
+
absoluteToTransformReady(url: string, options?: AbsoluteToTransformReadyOptionsInputType): string;
|
|
89
|
+
relativeToTransformReady(url: string, options?: RelativeToTransformReadyOptionsInputType): string;
|
|
90
|
+
transformReadyToAbsolute(url: string, options?: TransformReadyToAbsoluteOptionsInput): string;
|
|
91
|
+
transformReadyToRelative(url: string, options?: TransformReadyToRelativeOptionsInput): string;
|
|
92
|
+
htmlToTransformReady(html: string, itemPath: string | null | HtmlTransformOptionsInput, options?: HtmlTransformOptionsInput): string;
|
|
93
|
+
/**
|
|
94
|
+
* Convert relative URLs in html into absolute URLs
|
|
95
|
+
* @param {string} html
|
|
96
|
+
* @param {string} itemPath (path of current context)
|
|
97
|
+
* @param {Object} options
|
|
98
|
+
* @returns {object} htmlContent
|
|
99
|
+
* @description Takes html, blog url and item path and converts relative url into
|
|
100
|
+
* absolute urls. Returns an object. The html string can be accessed by calling `html()` on
|
|
101
|
+
* the variable that takes the result of this function
|
|
102
|
+
*/
|
|
103
|
+
htmlRelativeToAbsolute(html: string, itemPath: string | null | HtmlTransformOptionsInput, options?: HtmlTransformOptionsInput): string;
|
|
104
|
+
htmlRelativeToTransformReady(html: string, itemPath: string | null | RelativeToTransformReadyOptionsInputType, options?: RelativeToTransformReadyOptionsInputType): string;
|
|
105
|
+
htmlAbsoluteToRelative(html: string, options?: HtmlTransformOptionsInput): string;
|
|
106
|
+
htmlAbsoluteToTransformReady(html: string, options?: AbsoluteToTransformReadyOptionsInputType): string;
|
|
107
|
+
markdownToTransformReady(markdown: string, itemPath: string | null | MarkdownTransformOptionsInput, options?: MarkdownTransformOptionsInput): string;
|
|
108
|
+
markdownRelativeToAbsolute(markdown: string, itemPath: string | null | MarkdownTransformOptionsInput, options?: MarkdownTransformOptionsInput): string;
|
|
109
|
+
markdownRelativeToTransformReady(markdown: string, itemPath: string | null | MarkdownTransformOptionsInput, options?: MarkdownTransformOptionsInput): string;
|
|
110
|
+
markdownAbsoluteToRelative(markdown: string, options?: MarkdownTransformOptionsInput): string;
|
|
111
|
+
markdownAbsoluteToTransformReady(markdown: string, options?: AbsoluteToTransformReadyOptionsInputType): string;
|
|
112
|
+
mobiledocToTransformReady(serializedMobiledoc: string, itemPath: string | null | MobiledocTransformOptionsInput, options?: MobiledocTransformOptionsInput): string;
|
|
113
|
+
mobiledocRelativeToAbsolute(serializedMobiledoc: string, itemPath: string | null | MobiledocTransformOptionsInput, options?: MobiledocTransformOptionsInput): string;
|
|
114
|
+
mobiledocRelativeToTransformReady(serializedMobiledoc: string, itemPath: string | null | MobiledocTransformOptionsInput, options?: MobiledocTransformOptionsInput): string;
|
|
115
|
+
mobiledocAbsoluteToRelative(serializedMobiledoc: string, options?: MobiledocTransformOptionsInput): string;
|
|
116
|
+
mobiledocAbsoluteToTransformReady(serializedMobiledoc: string, options?: MobiledocTransformOptionsInput): string;
|
|
117
|
+
lexicalToTransformReady(serializedLexical: string, itemPath: string | null | LexicalTransformOptionsInput, options?: LexicalTransformOptionsInput): string;
|
|
118
|
+
lexicalRelativeToAbsolute(serializedLexical: string, itemPath: string | null | LexicalTransformOptionsInput, options?: LexicalTransformOptionsInput): string;
|
|
119
|
+
lexicalRelativeToTransformReady(serializedLexical: string, itemPath: string | null | LexicalTransformOptionsInput, options?: LexicalTransformOptionsInput): string;
|
|
120
|
+
lexicalAbsoluteToRelative(serializedLexical: string, options?: LexicalTransformOptionsInput): string;
|
|
121
|
+
lexicalAbsoluteToTransformReady(serializedLexical: string, options?: LexicalTransformOptionsInput): string;
|
|
122
|
+
plaintextToTransformReady(plaintext: string, options?: Record<string, unknown>): string;
|
|
123
|
+
/**
|
|
124
|
+
* Return whether the provided URL is part of the site (checks if same domain and within subdirectory)
|
|
125
|
+
* @param {URL} url
|
|
126
|
+
* @param {string} [context] describing the context for which you need to check a url
|
|
127
|
+
* @returns {boolean}
|
|
128
|
+
*/
|
|
129
|
+
isSiteUrl(url: URL, context?: string): boolean;
|
|
130
|
+
get isSSL(): typeof utils.isSSL;
|
|
131
|
+
get replacePermalink(): typeof utils.replacePermalink;
|
|
132
|
+
get deduplicateDoubleSlashes(): typeof utils.deduplicateDoubleSlashes;
|
|
133
|
+
/**
|
|
134
|
+
* If you request **any** image in Ghost, it get's served via
|
|
135
|
+
* http://your-blog.com/content/images/2017/01/02/author.png
|
|
136
|
+
*
|
|
137
|
+
* /content/images/ is a static prefix for serving images!
|
|
138
|
+
*
|
|
139
|
+
* But internally the image is located for example in your custom content path:
|
|
140
|
+
* my-content/another-dir/images/2017/01/02/author.png
|
|
141
|
+
*/
|
|
142
|
+
get STATIC_IMAGE_URL_PREFIX(): string;
|
|
143
|
+
get STATIC_FILES_URL_PREFIX(): string;
|
|
144
|
+
get STATIC_MEDIA_URL_PREFIX(): string;
|
|
145
|
+
get _utils(): typeof utils;
|
|
146
|
+
}
|
|
147
|
+
export {};
|