astro-accelerator-utils 0.2.2 → 0.2.4

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/index.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Accelerator } from "./lib/v1/accelerator.mjs";
1
2
  import * as PostFiltering from "./lib/postFiltering.mjs";
2
3
  import * as PostOrdering from "./lib/postOrdering.mjs";
3
- export { Factory, PostFiltering, PostOrdering };
4
+ export { Accelerator, PostFiltering, PostOrdering };
package/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { Factory } from './lib/v1/_factory.mjs';
1
+ import { Accelerator } from './lib/v1/accelerator.mjs';
2
2
 
3
3
  import * as PostFiltering from './lib/postFiltering.mjs';
4
4
  import * as PostOrdering from './lib/postOrdering.mjs';
5
5
 
6
6
  export {
7
- Factory,
7
+ Accelerator,
8
8
  PostFiltering,
9
9
  PostOrdering
10
10
  };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @typedef { import("../../types/Site").Site } Site
3
+ */
4
+ export class Accelerator {
5
+ /**
6
+ * @param {Site} site
7
+ */
8
+ constructor(site: Site);
9
+ cacheMaxAge: number;
10
+ dateOptions: Intl.DateTimeFormatOptions;
11
+ siteUrl: string;
12
+ get authors(): Authors;
13
+ get cache(): Cache;
14
+ get dateFormatter(): DateFormatter;
15
+ get markdown(): Markdown;
16
+ get navigation(): Navigation;
17
+ get paging(): Paging;
18
+ get posts(): Posts;
19
+ get taxonomy(): Taxonomy;
20
+ get urlFormatter(): UrlFormatter;
21
+ }
22
+ export type Site = import("../../types/Site").Site;
23
+ import { Authors } from "./authors.mjs";
24
+ import { Cache } from "./cache.mjs";
25
+ import { DateFormatter } from "./dates.mjs";
26
+ import { Markdown } from "./markdown.mjs";
27
+ import { Navigation } from "./navigation.mjs";
28
+ import { Paging } from "./paging.mjs";
29
+ import { Posts } from "./posts.mjs";
30
+ import { Taxonomy } from "./taxonomy.mjs";
31
+ import { UrlFormatter } from "./urls.mjs";
@@ -19,7 +19,7 @@ export class Accelerator {
19
19
  constructor(site) {
20
20
  this.cacheMaxAge = site.cacheMaxAge;
21
21
  this.dateOptions = site.dateOptions;
22
- this.siteUrl = site.siteUrl;
22
+ this.siteUrl = site.url;
23
23
  }
24
24
 
25
25
  get authors() {
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @typedef { import("../../types/AuthorList").AuthorList } AuthorList
3
+ * @typedef { import("../../types/Astro").MarkdownInstance } MarkdownInstance
4
+ * @typedef { import("../../types/Frontmatter").Frontmatter } Frontmatter
5
+ */
6
+ export class Authors {
7
+ /**
8
+ * Constructor
9
+ * @param {Posts} posts
10
+ */
11
+ constructor(posts: Posts);
12
+ posts: Posts;
13
+ /**
14
+ * Gets a list of authors, and exposes main author and contributors
15
+ * @param {Frontmatter} frontmatter
16
+ * @returns {AuthorList}
17
+ */
18
+ forPost(frontmatter: Frontmatter): AuthorList;
19
+ /**
20
+ * Get a single author by id/slug
21
+ * @param {string} slug
22
+ * @returns {MarkdownInstance}
23
+ */
24
+ info(slug: string): MarkdownInstance;
25
+ }
26
+ export type AuthorList = import("../../types/AuthorList").AuthorList;
27
+ export type MarkdownInstance = import("../../types/Astro").MarkdownInstance;
28
+ export type Frontmatter = import("../../types/Frontmatter").Frontmatter;
@@ -0,0 +1,43 @@
1
+ export class Cache {
2
+ /**
3
+ * Constructor
4
+ * @param {number} maxAge
5
+ */
6
+ constructor(maxAge: number);
7
+ maxAge: number;
8
+ /**
9
+ * Gets an item from the cache, falls back to supplied function
10
+ * @param {string} key
11
+ * @param {() => any} func
12
+ */
13
+ get(key: string, func: () => any): any;
14
+ /**
15
+ * Gets an item from the cache
16
+ * @param {string} key
17
+ * @returns {Promise<any>}
18
+ */
19
+ getItem(key: string): Promise<any>;
20
+ /**
21
+ * Adds an item to the cache
22
+ * @param {string} key
23
+ * @param {any} value
24
+ * @returns {Promise<void>}
25
+ */
26
+ setItem(key: string, value: any): Promise<void>;
27
+ /**
28
+ * Clears the cache
29
+ * @returns {Promise<void>}
30
+ */
31
+ clear(): Promise<void>;
32
+ /**
33
+ * Get's the path of the cache files
34
+ * @returns {string}
35
+ */
36
+ getCachePath(): string;
37
+ /**
38
+ * Gets the file path for a cache item
39
+ * @param {string} key
40
+ * @returns {string}
41
+ */
42
+ getItemPath(key: string): string;
43
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @typedef { import("../types/Site") } Site
3
+ */
4
+ export class DateFormatter {
5
+ /**
6
+ * Constructor
7
+ * @param {Intl.DateTimeFormatOptions} dateOptions
8
+ */
9
+ constructor(dateOptions: Intl.DateTimeFormatOptions);
10
+ dateOptions: Intl.DateTimeFormatOptions;
11
+ /**
12
+ * Returns the formatted pubDate
13
+ * @param {string | Date} date
14
+ * @param {string} lang
15
+ * @returns {string}
16
+ */
17
+ formatDate(date: string | Date, lang: string): string;
18
+ }
19
+ export type Site = any;
@@ -0,0 +1,20 @@
1
+ export class Markdown {
2
+ /**
3
+ * Converts markdown to HTML without wrapping in a <p>
4
+ * @param {string} markdown
5
+ * @returns {Promise<string>}
6
+ */
7
+ getInlineHtmlFrom(markdown: string): Promise<string>;
8
+ /**
9
+ * Converts markdown to HTML
10
+ * @param {string} markdown
11
+ * @returns {Promise<string>}
12
+ */
13
+ getHtmlFrom(markdown: string): Promise<string>;
14
+ /**
15
+ * Converts markdown to plain text
16
+ * @param {string} markdown
17
+ * @returns {Promise<string>}
18
+ */
19
+ getTextFrom(markdown: string): Promise<string>;
20
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @typedef { import("./posts.mjs").Posts } Posts
3
+ * @typedef { import("./taxonomy.mjs").Taxonomy } Taxonomy
4
+ * @typedef { import("./urls.mjs").UrlFormatter } UrlFormatter
5
+ * @typedef { import("../../types/Astro").MarkdownInstance } MarkdownInstance
6
+ * @typedef { import("../../types/NavPage").NavPage } NavPage
7
+ */
8
+ export class Navigation {
9
+ /**
10
+ * Constructor
11
+ * @param {Posts} posts
12
+ * @param {UrlFormatter} urlFormatter
13
+ * @param {Taxonomy} taxonomy
14
+ */
15
+ constructor(posts: Posts, urlFormatter: UrlFormatter, taxonomy: Taxonomy);
16
+ posts: import("./posts.mjs").Posts;
17
+ urlFormatter: import("./urls.mjs").UrlFormatter;
18
+ taxonomy: import("./taxonomy.mjs").Taxonomy;
19
+ /**
20
+ * Returns a list of breadcrumbs
21
+ * @param {URL} currentUrl
22
+ * @param {string} subfolder
23
+ * @returns {NavPage[]}
24
+ */
25
+ breadcrumbs(currentUrl: URL, subfolder: string): NavPage[];
26
+ /**
27
+ *
28
+ * @param {URL} currentUrl
29
+ * @param {string} subfolder
30
+ * @param {(NavPage | 'auto')[]} menu
31
+ * @returns {NavPage[]}
32
+ */
33
+ menu(currentUrl: URL, subfolder: string, menu: (NavPage | 'auto')[]): NavPage[];
34
+ /**
35
+ *
36
+ * @param {string} subfolder
37
+ * @returns {NavPage[]}
38
+ */
39
+ autoMenu(subfolder: string): NavPage[];
40
+ /**
41
+ *
42
+ * @param {URL} currentUrl
43
+ * @param {TranslationProvider} _
44
+ * @param {any} translations
45
+ * @param {string} subfolder
46
+ * @param {(NavPage | 'categories' | 'tags' | 'toptags')[]} menu
47
+ * @returns {NavPage[]}
48
+ */
49
+ footer(currentUrl: URL, _: TranslationProvider, translations: any, subfolder: string, menu: (NavPage | 'categories' | 'tags' | 'toptags')[]): NavPage[];
50
+ /**
51
+ *
52
+ * @param {TaxonomyLinks} links
53
+ * @param {TranslationProvider} _
54
+ * @param {any} translations
55
+ * @param {string} subfolder
56
+ * @param {TaxonomyList} entries
57
+ * @returns {NavPage[]}
58
+ */
59
+ getCategories(links: TaxonomyLinks, _: TranslationProvider, translations: any, subfolder: string, entries: TaxonomyList): NavPage[];
60
+ /**
61
+ *
62
+ * @param {TaxonomyLinks} links
63
+ * @param {TranslationProvider} _
64
+ * @param {any} translations
65
+ * @param {string} subfolder
66
+ * @param {TaxonomyList} entries
67
+ * @returns {NavPage[]}
68
+ */
69
+ getTags(links: TaxonomyLinks, _: TranslationProvider, translations: any, subfolder: string, entries: TaxonomyList): NavPage[];
70
+ /**
71
+ *
72
+ * @param {TaxonomyLinks} links
73
+ * @param {TranslationProvider} _
74
+ * @param {any} translations
75
+ * @param {string} subfolder
76
+ * @param {TaxonomyList} entries
77
+ * @returns {NavPage[]}
78
+ */
79
+ getTopTags(links: TaxonomyLinks, _: TranslationProvider, translations: any, subfolder: string, entries: TaxonomyList): NavPage[];
80
+ /**
81
+ * Walks a NavPage tree to set current page
82
+ * @param {NavPage[]} pages
83
+ * @param {URL} currentUrl
84
+ */
85
+ setCurrentPage(pages: NavPage[], currentUrl: URL): void;
86
+ /**
87
+ * Converts a MarkdownInstance into a NavPage
88
+ * @param {MarkdownInstance} page
89
+ * @returns {NavPage}
90
+ */
91
+ mapNavPage(page: MarkdownInstance): NavPage;
92
+ /**
93
+ * Checks whether the item is a NavPage
94
+ * @param {NavPage | 'auto' | 'tags' | 'toptags' | 'categories'} item
95
+ * @returns {item is NavPage}
96
+ */
97
+ isNavPage(item: NavPage | 'auto' | 'tags' | 'toptags' | 'categories'): item is import("../../types/NavPage").NavPage;
98
+ /**
99
+ * Pops matching page from array
100
+ * @param {MarkdownInstance[]} allPages
101
+ * @param {string} search
102
+ * @returns
103
+ */
104
+ popMatchingPage(allPages: MarkdownInstance[], search: string): import("../../types/Astro").MarkdownInstance;
105
+ }
106
+ export type Posts = import("./posts.mjs").Posts;
107
+ export type Taxonomy = import("./taxonomy.mjs").Taxonomy;
108
+ export type UrlFormatter = import("./urls.mjs").UrlFormatter;
109
+ export type MarkdownInstance = import("../../types/Astro").MarkdownInstance;
110
+ export type NavPage = import("../../types/NavPage").NavPage;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @typedef { import("../types/Link").Link } Link
3
+ */
4
+ export class Paging {
5
+ /**
6
+ * Provides a list of paging links, 1 ... 3 4 5 ... 7
7
+ * @param {number} limit
8
+ * @param {number} numberOfPages
9
+ * @param {number} currentPage
10
+ * @param {string} url
11
+ * @returns {Link[]}
12
+ */
13
+ links(limit: number, numberOfPages: number, currentPage: number, url: string): Link[];
14
+ }
15
+ export type Link = any;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @typedef { import("../../types/Astro").MarkdownInstance } MarkdownInstance
3
+ * @typedef { import("./cache.mjs").Cache } Cache
4
+ */
5
+ export class Posts {
6
+ /**
7
+ * Constructor
8
+ * @param {Cache} cache
9
+ * @param {() => MarkdownInstance[]} [fetchAll]
10
+ */
11
+ constructor(cache: Cache, fetchAll?: () => MarkdownInstance[]);
12
+ cache: import("./cache.mjs").Cache;
13
+ fetchAll: () => any;
14
+ /**
15
+ * Gets all markdown posts in the site
16
+ * @returns {MarkdownInstance[]}
17
+ */
18
+ all(): MarkdownInstance[];
19
+ /**
20
+ * Gets top-level markdown posts in the site
21
+ * @returns {MarkdownInstance[]}
22
+ */
23
+ root(subfolder: any): MarkdownInstance[];
24
+ }
25
+ export type MarkdownInstance = import("../../types/Astro").MarkdownInstance;
26
+ export type Cache = import("./cache.mjs").Cache;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @typedef { import("./cache.mjs").Cache } Cache
3
+ * @typedef { import("./posts.mjs").Posts } Posts
4
+ * @typedef { import("./urls.mjs").UrlFormatter } UrlFormatter
5
+ * @typedef { import("../../types/Site").Site } Site
6
+ * @typedef { import("../../types/Taxonomy").TaxonomyList } TaxonomyList
7
+ * @typedef { import("../../types/Taxonomy").TaxonomyEntry } TaxonomyEntry
8
+ * @typedef { import("../../types/Taxonomy").TaxonomyLinks } TaxonomyLinks
9
+ * @typedef { import("../../types/Astro").MarkdownInstance } MarkdownInstance
10
+ */
11
+ export class Taxonomy {
12
+ /**
13
+ * Constructor
14
+ * @param {Cache} cache
15
+ * @param {Posts} posts
16
+ * @param {UrlFormatter} urlFormatter
17
+ */
18
+ constructor(cache: Cache, posts: Posts, urlFormatter: UrlFormatter);
19
+ cache: import("./cache.mjs").Cache;
20
+ posts: import("./posts.mjs").Posts;
21
+ urlFormatter: import("./urls.mjs").UrlFormatter;
22
+ /**
23
+ *
24
+ * @returns {TaxonomyList}
25
+ */
26
+ all(): TaxonomyList;
27
+ /**
28
+ *
29
+ * @param {any} translations
30
+ * @param {(entry: any) => string} lang
31
+ * @param {string} subfolder
32
+ * @returns {TaxonomyLinks}
33
+ */
34
+ links(translations: any, lang: (entry: any) => string, subfolder: string): TaxonomyLinks;
35
+ /**
36
+ *
37
+ * @returns {TaxonomyList}
38
+ */
39
+ getTaxonomy(): TaxonomyList;
40
+ /**
41
+ * Sorts taxonomy entries by title
42
+ * @param {TaxonomyEntry} a
43
+ * @param {TaxonomyEntry} b
44
+ * @returns
45
+ */
46
+ sortByTitle(a: TaxonomyEntry, b: TaxonomyEntry): 0 | 1 | -1;
47
+ /**
48
+ * Sorts taxonomy entries by title
49
+ * @param {TaxonomyEntry} a
50
+ * @param {TaxonomyEntry} b
51
+ * @returns
52
+ */
53
+ sortByVolume(a: TaxonomyEntry, b: TaxonomyEntry): number;
54
+ }
55
+ export type Cache = import("./cache.mjs").Cache;
56
+ export type Posts = import("./posts.mjs").Posts;
57
+ export type UrlFormatter = import("./urls.mjs").UrlFormatter;
58
+ export type Site = import("../../types/Site").Site;
59
+ export type TaxonomyList = import("../../types/Taxonomy").TaxonomyList;
60
+ export type TaxonomyEntry = import("../../types/Taxonomy").TaxonomyEntry;
61
+ export type TaxonomyLinks = import("../../types/Taxonomy").TaxonomyLinks;
62
+ export type MarkdownInstance = import("../../types/Astro").MarkdownInstance;
@@ -0,0 +1,20 @@
1
+ export class UrlFormatter {
2
+ /**
3
+ * Constructor
4
+ * @param {string} siteUrl
5
+ */
6
+ constructor(siteUrl: string);
7
+ siteUrl: string;
8
+ /**
9
+ * Ensures trailing slash is used
10
+ * @param {URL} url
11
+ * @returns {URL}
12
+ */
13
+ addSlashToUrl(url: URL): URL;
14
+ /**
15
+ * Ensures trailing slash is used
16
+ * @param {string | undefined} address
17
+ * @returns {string}
18
+ */
19
+ addSlashToAddress(address: string | undefined): string;
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-accelerator-utils",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Astro utilities for Astro Accelerator.",
5
5
  "main": "index.mjs",
6
6
  "type": "module",
@@ -0,0 +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
+ }
@@ -0,0 +1,4 @@
1
+ export interface BannerImage {
2
+ src: string;
3
+ alt: string;
4
+ }
@@ -0,0 +1,10 @@
1
+ export interface NavPage {
2
+ section?: string;
3
+ title: string;
4
+ url: string;
5
+ order: number;
6
+ isOpen: boolean;
7
+ ariaCurrent: 'page' | false;
8
+ children: NavPage[];
9
+ rel?: string;
10
+ }
@@ -0,0 +1,35 @@
1
+ export type Site = {
2
+ url: string;
3
+ dateOptions: Intl.DateTimeFormatOptions;
4
+ subfolder: string;
5
+ feedUrl: string;
6
+ title: string;
7
+ description: string;
8
+ defaultLanguage: string;
9
+ themeColor: string;
10
+ owner: string;
11
+ default: {
12
+ lang: string;
13
+ locale: string;
14
+ dir: string;
15
+ };
16
+ search: {
17
+ fallbackUrl: 'https://www.google.com/search' | string;
18
+ fallbackSite: 'q' | string;
19
+ fallbackQuery: 'q' | string;
20
+ };
21
+ pageSize: number;
22
+ pageLinks: number;
23
+ rssLimit: number;
24
+ cacheMaxAge: number;
25
+ featureFlags: {
26
+ codeBlocks: 'copy'[];
27
+ figures: 'enlarge'[];
28
+ youTubeLinks: 'embed'[];
29
+ };
30
+ images: {
31
+ contentSize: string;
32
+ listerSize: string;
33
+ authorSize: string;
34
+ };
35
+ };
@@ -0,0 +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
+ }