astro-accelerator-utils 0.3.6 → 0.3.8

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.
Files changed (42) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +19 -19
  3. package/index.d.mts +4 -4
  4. package/index.mjs +9 -9
  5. package/lib/postFiltering.d.mts +48 -48
  6. package/lib/postFiltering.mjs +116 -116
  7. package/lib/postOrdering.d.mts +32 -32
  8. package/lib/postOrdering.mjs +51 -51
  9. package/lib/v1/accelerator.d.mts +36 -36
  10. package/lib/v1/accelerator.mjs +70 -70
  11. package/lib/v1/authors.d.mts +28 -28
  12. package/lib/v1/authors.mjs +71 -71
  13. package/lib/v1/cache.d.mts +43 -43
  14. package/lib/v1/cache.mjs +99 -99
  15. package/lib/v1/dates.d.mts +19 -19
  16. package/lib/v1/dates.mjs +26 -26
  17. package/lib/v1/markdown.d.mts +20 -20
  18. package/lib/v1/markdown.mjs +45 -45
  19. package/lib/v1/navigation.d.mts +111 -111
  20. package/lib/v1/navigation.mjs +446 -427
  21. package/lib/v1/paging.d.mts +15 -15
  22. package/lib/v1/paging.mjs +77 -77
  23. package/lib/v1/posts.d.mts +26 -26
  24. package/lib/v1/posts.mjs +47 -47
  25. package/lib/v1/statistics-stub.d.mts +5 -5
  26. package/lib/v1/statistics-stub.mjs +9 -9
  27. package/lib/v1/statistics.d.mts +39 -39
  28. package/lib/v1/statistics.mjs +78 -78
  29. package/lib/v1/taxonomy.d.mts +62 -62
  30. package/lib/v1/taxonomy.mjs +144 -144
  31. package/lib/v1/urls.d.mts +40 -40
  32. package/lib/v1/urls.mjs +104 -104
  33. package/package.json +3 -3
  34. package/types/Astro.d.ts +19 -19
  35. package/types/AuthorList.d.ts +8 -8
  36. package/types/BannerImage.d.ts +4 -4
  37. package/types/Frontmatter.d.ts +30 -30
  38. package/types/Link.d.ts +6 -6
  39. package/types/NavPage.d.ts +22 -22
  40. package/types/PagePredicate.d.ts +2 -2
  41. package/types/Site.d.ts +43 -43
  42. package/types/Taxonomy.d.ts +15 -15
package/lib/v1/urls.mjs CHANGED
@@ -1,105 +1,105 @@
1
- export class UrlFormatter {
2
- /**
3
- * Constructor
4
- * @param {string} siteUrl
5
- * @param {string} subfolder
6
- * @param {boolean} useTrailingUrlSlash
7
- */
8
- constructor(siteUrl, subfolder, useTrailingUrlSlash) {
9
- this.siteUrl = siteUrl;
10
- this.subfolder = subfolder;
11
- this.useTrailingUrlSlash = useTrailingUrlSlash;
12
- }
13
-
14
- /** Uses config to decide whether to add or remove trailing slashes
15
- * @param {URL} url
16
- * @returns {URL}
17
- */
18
- formatUrl(url) {
19
- if (!url) {
20
- return new URL(this.siteUrl);
21
- }
22
-
23
- if (this.useTrailingUrlSlash) {
24
- // Add slash
25
- url.pathname += url.pathname.endsWith('/')
26
- ? ''
27
- : '/';
28
- } else {
29
- // Remove slash
30
- if (url.pathname.endsWith('/')) {
31
- url.pathname = url.pathname.substring(0, url.pathname.length - 1);
32
- }
33
- }
34
-
35
- return url;
36
- }
37
-
38
- /**
39
- * Ensures trailing slash is used
40
- * @param {string | undefined} address
41
- * @returns {string}
42
- */
43
- formatAddress(address) {
44
- if (!address) {
45
- // Handle null or empty addresses
46
- address = '/';
47
- }
48
-
49
- if (address.indexOf('//') > -1) {
50
- // Don't mess with absolute addresses
51
- return address;
52
- }
53
-
54
- const url = this.formatUrl(new URL(address, this.siteUrl));
55
- return url.pathname + url.search;
56
- }
57
-
58
- /**
59
- * Ensures trailing slash is used
60
- * @param {URL} url
61
- * @returns {URL}
62
- */
63
- addSlashToUrl(url) {
64
- if (!url) {
65
- return new URL(this.siteUrl);
66
- }
67
-
68
- url.pathname += url.pathname.endsWith('/')
69
- ? ''
70
- : '/';
71
-
72
- return url;
73
- }
74
-
75
- /**
76
- * Ensures trailing slash is used
77
- * @param {string | undefined} address
78
- * @returns {string}
79
- */
80
- addSlashToAddress(address) {
81
- if (!address) {
82
- // Handle null or empty addresses
83
- address = '/';
84
- }
85
-
86
- if (address.indexOf('//') > -1) {
87
- // Don't mess with absolute addresses
88
- return address;
89
- }
90
-
91
- const url = this.addSlashToUrl(new URL(address, this.siteUrl));
92
- return url.pathname + url.search;
93
- }
94
-
95
- /**
96
- * Gets the author id from an address
97
- * @param {URL} url
98
- */
99
- getAuthorId(url) {
100
- const index = (this.subfolder.length === 0)
101
- ? 2 // i.e. /authors/steve-fenton/
102
- : 3 // i.e. /subfolder/authors/steve-fenton/
103
- return url.pathname.split('/')[index];
104
- }
1
+ export class UrlFormatter {
2
+ /**
3
+ * Constructor
4
+ * @param {string} siteUrl
5
+ * @param {string} subfolder
6
+ * @param {boolean} useTrailingUrlSlash
7
+ */
8
+ constructor(siteUrl, subfolder, useTrailingUrlSlash) {
9
+ this.siteUrl = siteUrl;
10
+ this.subfolder = subfolder;
11
+ this.useTrailingUrlSlash = useTrailingUrlSlash;
12
+ }
13
+
14
+ /** Uses config to decide whether to add or remove trailing slashes
15
+ * @param {URL} url
16
+ * @returns {URL}
17
+ */
18
+ formatUrl(url) {
19
+ if (!url) {
20
+ return new URL(this.siteUrl);
21
+ }
22
+
23
+ if (this.useTrailingUrlSlash) {
24
+ // Add slash
25
+ url.pathname += url.pathname.endsWith('/')
26
+ ? ''
27
+ : '/';
28
+ } else {
29
+ // Remove slash
30
+ if (url.pathname.endsWith('/')) {
31
+ url.pathname = url.pathname.substring(0, url.pathname.length - 1);
32
+ }
33
+ }
34
+
35
+ return url;
36
+ }
37
+
38
+ /**
39
+ * Ensures trailing slash is used
40
+ * @param {string | undefined} address
41
+ * @returns {string}
42
+ */
43
+ formatAddress(address) {
44
+ if (!address) {
45
+ // Handle null or empty addresses
46
+ address = '/';
47
+ }
48
+
49
+ if (address.indexOf('//') > -1) {
50
+ // Don't mess with absolute addresses
51
+ return address;
52
+ }
53
+
54
+ const url = this.formatUrl(new URL(address, this.siteUrl));
55
+ return url.pathname + url.search;
56
+ }
57
+
58
+ /**
59
+ * Ensures trailing slash is used
60
+ * @param {URL} url
61
+ * @returns {URL}
62
+ */
63
+ addSlashToUrl(url) {
64
+ if (!url) {
65
+ return new URL(this.siteUrl);
66
+ }
67
+
68
+ url.pathname += url.pathname.endsWith('/')
69
+ ? ''
70
+ : '/';
71
+
72
+ return url;
73
+ }
74
+
75
+ /**
76
+ * Ensures trailing slash is used
77
+ * @param {string | undefined} address
78
+ * @returns {string}
79
+ */
80
+ addSlashToAddress(address) {
81
+ if (!address) {
82
+ // Handle null or empty addresses
83
+ address = '/';
84
+ }
85
+
86
+ if (address.indexOf('//') > -1) {
87
+ // Don't mess with absolute addresses
88
+ return address;
89
+ }
90
+
91
+ const url = this.addSlashToUrl(new URL(address, this.siteUrl));
92
+ return url.pathname + url.search;
93
+ }
94
+
95
+ /**
96
+ * Gets the author id from an address
97
+ * @param {URL} url
98
+ */
99
+ getAuthorId(url) {
100
+ const index = (this.subfolder.length === 0)
101
+ ? 2 // i.e. /authors/steve-fenton/
102
+ : 3 // i.e. /subfolder/authors/steve-fenton/
103
+ return url.pathname.split('/')[index];
104
+ }
105
105
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "astro-accelerator-utils",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "Astro utilities for Astro Accelerator.",
5
5
  "main": "index.mjs",
6
6
  "type": "module",
7
- "packageManager": "pnpm@8.7.0",
7
+ "packageManager": "pnpm@9.1.4",
8
8
  "files": [
9
9
  "index.mjs",
10
10
  "index.d.mts",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "homepage": "https://astro.stevefenton.co.uk/",
34
34
  "devDependencies": {
35
- "@types/node": "^18.19.7",
35
+ "@types/node": "^18.19.39",
36
36
  "jest": "^29.7.0",
37
37
  "jest-spec": "^0.0.3",
38
38
  "rehype-stringify": "^9.0.4",
package/types/Astro.d.ts CHANGED
@@ -1,19 +1,19 @@
1
- import { Frontmatter } from "./Frontmatter";
2
- export type MarkdownInstance = {
3
- frontmatter: Frontmatter;
4
- /** Absolute file path (e.g. `/home/user/projects/.../file.md`) */
5
- file: string;
6
- /** Browser URL for files under `/src/pages` (e.g. `/en/guides/markdown-content`) */
7
- url: string | undefined;
8
- /** Component to render content in `.astro` files. Usage: `<Content />` */
9
- Content: any;
10
- /** raw Markdown file content, excluding layout HTML and YAML frontmatter */
11
- rawContent(): string;
12
- /** Markdown file compiled to HTML, excluding layout HTML */
13
- compiledContent(): string;
14
- /** List of headings (h1 -> h6) with associated metadata */
15
- getHeadings(): any[];
16
- /** @deprecated Renamed to `getHeadings()` */
17
- getHeaders(): void;
18
- default: any;
19
- };
1
+ import { Frontmatter } from "./Frontmatter";
2
+ export type MarkdownInstance = {
3
+ frontmatter: Frontmatter;
4
+ /** Absolute file path (e.g. `/home/user/projects/.../file.md`) */
5
+ file: string;
6
+ /** Browser URL for files under `/src/pages` (e.g. `/en/guides/markdown-content`) */
7
+ url: string | undefined;
8
+ /** Component to render content in `.astro` files. Usage: `<Content />` */
9
+ Content: any;
10
+ /** raw Markdown file content, excluding layout HTML and YAML frontmatter */
11
+ rawContent(): string;
12
+ /** Markdown file compiled to HTML, excluding layout HTML */
13
+ compiledContent(): string;
14
+ /** List of headings (h1 -> h6) with associated metadata */
15
+ getHeadings(): any[];
16
+ /** @deprecated Renamed to `getHeadings()` */
17
+ getHeaders(): void;
18
+ default: any;
19
+ };
@@ -1,8 +1,8 @@
1
- import type { MarkdownInstance } from "./Astro";
2
- import type { BannerImage } from "./BannerImage";
3
- export interface AuthorList {
4
- image: BannerImage | null;
5
- writers: MarkdownInstance[];
6
- mainAuthor: MarkdownInstance | null;
7
- contributors: MarkdownInstance[];
8
- }
1
+ import type { MarkdownInstance } from "./Astro";
2
+ import type { BannerImage } from "./BannerImage";
3
+ export interface AuthorList {
4
+ image: BannerImage | null;
5
+ writers: MarkdownInstance[];
6
+ mainAuthor: MarkdownInstance | null;
7
+ contributors: MarkdownInstance[];
8
+ }
@@ -1,4 +1,4 @@
1
- export interface BannerImage {
2
- src: string;
3
- alt: string;
4
- }
1
+ export interface BannerImage {
2
+ src: string;
3
+ alt: string;
4
+ }
@@ -1,30 +1,30 @@
1
- export interface Frontmatter {
2
- layout: string;
3
- title: string;
4
- titleAdditional?: string;
5
- subtitle?: string;
6
- pubDate: Date;
7
- modDate?: Date;
8
- tags?: string[];
9
- id?: string;
10
- authors?: string[];
11
- keywords?: string;
12
- description?: string;
13
- summary?: string;
14
- categories?: string[];
15
- navTitle?: string;
16
- navSection?: string;
17
- navOrder?: number;
18
- bannerImage?: {
19
- src: string;
20
- alt: string;
21
- };
22
- dir?: 'ltr' | 'rtl';
23
- lang?: string;
24
- paged?: boolean;
25
- navSearch?: boolean;
26
- navSitemap?: boolean;
27
- navMenu?: boolean;
28
- robots?: string;
29
- redirect?: string;
30
- }
1
+ export interface Frontmatter {
2
+ layout: string;
3
+ title: string;
4
+ titleAdditional?: string;
5
+ subtitle?: string;
6
+ pubDate: Date;
7
+ modDate?: Date;
8
+ tags?: string[];
9
+ id?: string;
10
+ authors?: string[];
11
+ keywords?: string;
12
+ description?: string;
13
+ summary?: string;
14
+ categories?: string[];
15
+ navTitle?: string;
16
+ navSection?: string;
17
+ navOrder?: number;
18
+ bannerImage?: {
19
+ src: string;
20
+ alt: string;
21
+ };
22
+ dir?: 'ltr' | 'rtl';
23
+ lang?: string;
24
+ paged?: boolean;
25
+ navSearch?: boolean;
26
+ navSitemap?: boolean;
27
+ navMenu?: boolean;
28
+ robots?: string;
29
+ redirect?: string;
30
+ }
package/types/Link.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export interface Link {
2
- title: string;
3
- url: string;
4
- ariaCurrent: 'page' | false;
5
- class: string;
6
- }
1
+ export interface Link {
2
+ title: string;
3
+ url: string;
4
+ ariaCurrent: 'page' | false;
5
+ class: string;
6
+ }
@@ -1,22 +1,22 @@
1
- export interface NavPage {
2
- section?: string;
3
- fullTitle: string;
4
- title: string;
5
- url: string;
6
- order: number;
7
- isOpen: boolean;
8
- ariaCurrent: 'page' | false;
9
- children: NavPage[];
10
- rel?: string;
11
- }
12
- export interface MenuItem {
13
- title: string;
14
- order: number;
15
- isOpen?: boolean;
16
- ariaCurrent?: 'page' | false;
17
- fullTitle?: string;
18
- children?: MenuItem[];
19
- section?: string;
20
- url?: string;
21
- rel?: string;
22
- }
1
+ export interface NavPage {
2
+ section?: string;
3
+ fullTitle: string;
4
+ title: string;
5
+ url: string;
6
+ order: number;
7
+ isOpen: boolean;
8
+ ariaCurrent: 'page' | false;
9
+ children: NavPage[];
10
+ rel?: string;
11
+ }
12
+ export interface MenuItem {
13
+ title: string;
14
+ order: number;
15
+ isOpen?: boolean;
16
+ ariaCurrent?: 'page' | false;
17
+ fullTitle?: string;
18
+ children?: MenuItem[];
19
+ section?: string;
20
+ url?: string;
21
+ rel?: string;
22
+ }
@@ -1,2 +1,2 @@
1
- import { MarkdownInstance } from "./Astro";
2
- export type PagePredicate = (value: MarkdownInstance, index: number, array: MarkdownInstance[]) => boolean;
1
+ import { MarkdownInstance } from "./Astro";
2
+ export type PagePredicate = (value: MarkdownInstance, index: number, array: MarkdownInstance[]) => boolean;
package/types/Site.d.ts CHANGED
@@ -1,43 +1,43 @@
1
- export type Site = {
2
- url: string;
3
- useTrailingUrlSlash?: boolean;
4
- captureStatistics: boolean;
5
- dateOptions: Intl.DateTimeFormatOptions;
6
- subfolder: string;
7
- feedUrl: string;
8
- title: string;
9
- description: string;
10
- defaultLanguage: string;
11
- themeColor: string;
12
- owner: string;
13
- default: {
14
- lang: string;
15
- locale: string;
16
- dir: string;
17
- };
18
- search: {
19
- fallbackUrl: 'https://www.google.com/search' | string;
20
- fallbackSite: 'q' | string;
21
- fallbackQuery: 'q' | string;
22
- };
23
- pageSize: number;
24
- pageLinks: number;
25
- rssLimit: number;
26
- cacheMaxAge: number;
27
- featureFlags: {
28
- stickyNav: {
29
- top: number;
30
- };
31
- codeBlocks: 'copy'[];
32
- figures: 'enlarge'[];
33
- youTubeLinks: 'embed'[];
34
- headers: 'link'[];
35
- details: 'tabs'[];
36
- search: 'dialog'[];
37
- };
38
- images: {
39
- contentSize: string;
40
- listerSize: string;
41
- authorSize: string;
42
- };
43
- };
1
+ export type Site = {
2
+ url: string;
3
+ useTrailingUrlSlash?: boolean;
4
+ captureStatistics: boolean;
5
+ dateOptions: Intl.DateTimeFormatOptions;
6
+ subfolder: string;
7
+ feedUrl: string;
8
+ title: string;
9
+ description: string;
10
+ defaultLanguage: string;
11
+ themeColor: string;
12
+ owner: string;
13
+ default: {
14
+ lang: string;
15
+ locale: string;
16
+ dir: string;
17
+ };
18
+ search: {
19
+ fallbackUrl: 'https://www.google.com/search' | string;
20
+ fallbackSite: 'q' | string;
21
+ fallbackQuery: 'q' | string;
22
+ };
23
+ pageSize: number;
24
+ pageLinks: number;
25
+ rssLimit: number;
26
+ cacheMaxAge: number;
27
+ featureFlags: {
28
+ stickyNav: {
29
+ top: number;
30
+ };
31
+ codeBlocks: 'copy'[];
32
+ figures: 'enlarge'[];
33
+ youTubeLinks: 'embed'[];
34
+ headers: 'link'[];
35
+ details: 'tabs'[];
36
+ search: 'dialog' | 'headings'[];
37
+ };
38
+ images: {
39
+ contentSize: string;
40
+ listerSize: string;
41
+ authorSize: string;
42
+ };
43
+ };
@@ -1,15 +1,15 @@
1
- export interface TaxonomyEntry {
2
- title: string;
3
- count: number;
4
- }
5
- export interface TaxonomyList {
6
- tags: TaxonomyEntry[];
7
- topTags: TaxonomyEntry[];
8
- categories: TaxonomyEntry[];
9
- }
10
- export interface TaxonomyLinks {
11
- tag: string;
12
- category: string;
13
- getCategoryLink: (category: string) => string;
14
- getTagLink: (tag: string) => string;
15
- }
1
+ export interface TaxonomyEntry {
2
+ title: string;
3
+ count: number;
4
+ }
5
+ export interface TaxonomyList {
6
+ tags: TaxonomyEntry[];
7
+ topTags: TaxonomyEntry[];
8
+ categories: TaxonomyEntry[];
9
+ }
10
+ export interface TaxonomyLinks {
11
+ tag: string;
12
+ category: string;
13
+ getCategoryLink: (category: string) => string;
14
+ getTagLink: (tag: string) => string;
15
+ }