astro-accelerator-utils 0.2.6 → 0.2.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.
package/README.md CHANGED
@@ -4,3 +4,6 @@
4
4
 
5
5
  Utility classes for Astro Accelerator
6
6
 
7
+ [![npm](https://img.shields.io/npm/v/astro-accelerator-utils?color=blue&style=plastic)](https://www.npmjs.com/package/astro-accelerator-utils/)
8
+ [![npm](https://img.shields.io/npm/dm/astro-accelerator-utils?style=plastic)](https://www.npmjs.com/package/astro-accelerator-utils/)
9
+
@@ -9,6 +9,7 @@ export class Accelerator {
9
9
  cacheMaxAge: number;
10
10
  dateOptions: Intl.DateTimeFormatOptions;
11
11
  siteUrl: string;
12
+ subfolder: string;
12
13
  get authors(): Authors;
13
14
  get cache(): Cache;
14
15
  get dateFormatter(): DateFormatter;
@@ -20,6 +20,7 @@ export class Accelerator {
20
20
  this.cacheMaxAge = site.cacheMaxAge;
21
21
  this.dateOptions = site.dateOptions;
22
22
  this.siteUrl = site.url;
23
+ this.subfolder = site.subfolder;
23
24
  }
24
25
 
25
26
  get authors() {
@@ -39,7 +40,7 @@ export class Accelerator {
39
40
  }
40
41
 
41
42
  get navigation() {
42
- return new Navigation(this.posts, this.UrlFormatter);
43
+ return new Navigation(this.posts, this.urlFormatter, this.taxonomy);
43
44
  }
44
45
 
45
46
  get paging() {
@@ -51,10 +52,10 @@ export class Accelerator {
51
52
  }
52
53
 
53
54
  get taxonomy() {
54
- return new Taxonomy(this.cache, this.posts, this.UrlFormatter);
55
+ return new Taxonomy(this.cache, this.posts, this.urlFormatter);
55
56
  }
56
57
 
57
58
  get urlFormatter() {
58
- return new UrlFormatter(this.siteUrl)
59
+ return new UrlFormatter(this.siteUrl, this.subfolder)
59
60
  }
60
61
  }
package/lib/v1/urls.d.mts CHANGED
@@ -2,9 +2,11 @@ export class UrlFormatter {
2
2
  /**
3
3
  * Constructor
4
4
  * @param {string} siteUrl
5
+ * @param {string} subfolder
5
6
  */
6
- constructor(siteUrl: string);
7
+ constructor(siteUrl: string, subfolder: string);
7
8
  siteUrl: string;
9
+ subfolder: string;
8
10
  /**
9
11
  * Ensures trailing slash is used
10
12
  * @param {URL} url
@@ -17,4 +19,9 @@ export class UrlFormatter {
17
19
  * @returns {string}
18
20
  */
19
21
  addSlashToAddress(address: string | undefined): string;
22
+ /**
23
+ * Gets the author id from an address
24
+ * @param {URL} url
25
+ */
26
+ getAuthorId(url: URL): string;
20
27
  }
package/lib/v1/urls.mjs CHANGED
@@ -2,9 +2,11 @@ export class UrlFormatter {
2
2
  /**
3
3
  * Constructor
4
4
  * @param {string} siteUrl
5
+ * @param {string} subfolder
5
6
  */
6
- constructor(siteUrl) {
7
+ constructor(siteUrl, subfolder) {
7
8
  this.siteUrl = siteUrl;
9
+ this.subfolder = subfolder;
8
10
  }
9
11
 
10
12
  /**
@@ -43,4 +45,15 @@ export class UrlFormatter {
43
45
  const url = this.addSlashToUrl(new URL(address, this.siteUrl));
44
46
  return url.pathname + url.search;
45
47
  }
48
+
49
+ /**
50
+ * Gets the author id from an address
51
+ * @param {URL} url
52
+ */
53
+ getAuthorId(url) {
54
+ const index = (this.subfolder.length === 0)
55
+ ? 2 // i.e. /authors/steve-fenton/
56
+ : 3 // i.e. /subfolder/authors/steve-fenton/
57
+ return url.pathname.split('/')[index];
58
+ }
46
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-accelerator-utils",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Astro utilities for Astro Accelerator.",
5
5
  "main": "index.mjs",
6
6
  "type": "module",