astro-accelerator 0.0.25 → 0.0.26

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 (32) hide show
  1. package/package.json +2 -2
  2. package/src/pages/articles/[page].astro +5 -5
  3. package/src/pages/articles/feed.xml.ts +3 -3
  4. package/src/pages/authors/[author]/[page].astro +5 -5
  5. package/src/pages/category/[category]/[page].astro +5 -5
  6. package/src/pages/report/missing-banner.astro +3 -3
  7. package/src/pages/report/missing-meta.astro +3 -3
  8. package/src/pages/report/missing-pubdate.astro +2 -2
  9. package/src/pages/report/oldest-content.astro +3 -3
  10. package/src/pages/search.json.ts +3 -3
  11. package/src/pages/sitemap.xml.ts +3 -3
  12. package/src/pages/tag/[tag]/[page].astro +5 -5
  13. package/src/themes/accelerator/components/ArticleList.astro +3 -3
  14. package/src/themes/accelerator/components/Authors.astro +5 -5
  15. package/src/themes/accelerator/components/AuthorsMini.astro +3 -3
  16. package/src/themes/accelerator/components/Breadcrumbs.astro +2 -2
  17. package/src/themes/accelerator/components/Header.astro +3 -3
  18. package/src/themes/accelerator/components/HtmlHead.astro +2 -2
  19. package/src/themes/accelerator/components/NavigationItem.astro +2 -2
  20. package/src/themes/accelerator/components/Paging.astro +4 -4
  21. package/src/themes/accelerator/components/Related.astro +5 -5
  22. package/src/themes/accelerator/layouts/Author.astro +2 -2
  23. package/src/themes/accelerator/utilities/Authors.ts +3 -4
  24. package/src/themes/accelerator/utilities/Breadcrumbs.ts +2 -2
  25. package/src/themes/accelerator/utilities/Footer.ts +14 -15
  26. package/src/themes/accelerator/utilities/Languages.ts +5 -1
  27. package/src/themes/accelerator/utilities/NavPage.ts +2 -2
  28. package/src/themes/accelerator/utilities/Navigation.ts +7 -7
  29. package/src/themes/accelerator/utilities/PageQueries.ts +9 -26
  30. package/src/themes/accelerator/utilities/Taxonomy.ts +17 -9
  31. package/src/themes/accelerator/utilities/custom-markdown.mjs +18 -3
  32. package/src/themes/accelerator/utilities/img.mjs +14 -1
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.25",
2
+ "version": "0.0.26",
3
3
  "author": "Steve Fenton",
4
4
  "name": "astro-accelerator",
5
5
  "description": "A super-lightweight, accessible, SEO-friendly starter project for Astro",
@@ -26,7 +26,7 @@
26
26
  "dependencies": {
27
27
  "@squoosh/lib": "^0.4.0",
28
28
  "astro": "^1.6.6",
29
- "astro-accelerator-utils": "^0.0.18",
29
+ "astro-accelerator-utils": "^0.0.24",
30
30
  "hast-util-from-selector": "^2.0.0",
31
31
  "remark-directive": "^2.0.1"
32
32
  },
@@ -6,7 +6,7 @@ import { Translations, Lang } from '@util/Languages';
6
6
  import type { Page, MarkdownInstance } from 'astro';
7
7
  import { Frontmatter, SITE } from '@config';
8
8
  import { getPageLinks } from '@util/PageLinks';
9
- import { isListable, sortByPubDateDesc, getItem, setItem } from 'astro-accelerator-utils';
9
+ import { Cache, PostFiltering, PostOrdering } from 'astro-accelerator-utils';
10
10
  import Default from 'src/layouts/Default.astro';
11
11
  import ArticleList from '@components/ArticleList.astro';
12
12
  import Paging from '@components/Paging.astro';
@@ -41,7 +41,7 @@ type CacheData = {
41
41
  export async function getCacheData() {
42
42
  const key = 'pages_articles_[page]';
43
43
 
44
- let cacheData: CacheData = await getItem(key);
44
+ let cacheData: CacheData = await Cache.getItem(key);
45
45
 
46
46
  if (cacheData == null) {
47
47
  // This uses a relative glob, so we only look in the current collection
@@ -50,10 +50,10 @@ export async function getCacheData() {
50
50
  cacheData = { posts: []};
51
51
 
52
52
  cacheData.posts = sourcePosts
53
- .filter(isListable)
54
- .sort(sortByPubDateDesc);
53
+ .filter(PostFiltering.isListable)
54
+ .sort(PostOrdering.sortByPubDateDesc);
55
55
 
56
- await setItem(key, cacheData);
56
+ await Cache.setItem(key, cacheData);
57
57
  }
58
58
 
59
59
  return cacheData;
@@ -2,7 +2,7 @@
2
2
 
3
3
  // Generates an ATOM feed of recent posts
4
4
  import { SITE } from '@config';
5
- import { addSlashToAddress, isListable } from 'astro-accelerator-utils';
5
+ import { PostFiltering, Urls } from 'astro-accelerator-utils';
6
6
  import { getTextFrom } from '@util/Markdown';
7
7
 
8
8
  async function getData() {
@@ -14,7 +14,7 @@ async function getData() {
14
14
  for (const path in allArticles) {
15
15
  const article: any = await allArticles[path]();
16
16
 
17
- if (isListable(article)) {
17
+ if (PostFiltering.isListable(article)) {
18
18
  article.frontmatter.title = await getTextFrom(article.frontmatter.title ?? '');
19
19
 
20
20
  articles.push({
@@ -33,7 +33,7 @@ async function getData() {
33
33
  <entry>
34
34
  <title>${a.frontmatter.title ?? ''}</title>
35
35
  <link href="${ SITE.url + a.url }" />
36
- <id>${ SITE.url + addSlashToAddress(a.url, SITE) }</id>
36
+ <id>${ SITE.url + Urls.addSlashToAddress(a.url, SITE) }</id>
37
37
  <published>${ a.frontmatter.pubDate }</published>
38
38
  <updated>${ a.frontmatter.pubDate ?? a.frontmatter.pubDate }</updated>
39
39
  <summary>${ a.frontmatter.description ?? '' }</summary>
@@ -6,7 +6,7 @@ import { Translations, Lang } from '@util/Languages';
6
6
  import type { Page, MarkdownInstance } from 'astro';
7
7
  import { SITE, Frontmatter } from '@config';
8
8
  import { getPageLinks } from '@util/PageLinks';
9
- import { isListable, sortByPubDateDesc, getItem, setItem } from 'astro-accelerator-utils';
9
+ import { Cache, PostFiltering, PostOrdering } from 'astro-accelerator-utils';
10
10
  import { getAuthorInfo } from '@util/PageQueries';
11
11
  import Default from '@layouts/Default.astro';
12
12
  import ArticleList from '@components/ArticleList.astro';
@@ -42,7 +42,7 @@ type CacheData = {
42
42
  export async function getCacheData() {
43
43
  const key = 'pages_authors_[author]_[page]';
44
44
 
45
- let cacheData: CacheData = await getItem(key);
45
+ let cacheData: CacheData = await Cache.getItem(key);
46
46
 
47
47
  if (cacheData == null) {
48
48
  const sourcePosts = await Astro.glob('../../**/*.md');
@@ -50,8 +50,8 @@ export async function getCacheData() {
50
50
  cacheData = { posts: [], authors: []};
51
51
 
52
52
  cacheData.posts = sourcePosts
53
- .filter(isListable)
54
- .sort(sortByPubDateDesc);
53
+ .filter(PostFiltering.isListable)
54
+ .sort(PostOrdering.sortByPubDateDesc);
55
55
 
56
56
  cacheData.posts.forEach(p => {
57
57
  const auths: string[] = p.frontmatter.authors ?? [];
@@ -65,7 +65,7 @@ export async function getCacheData() {
65
65
  });
66
66
  });
67
67
 
68
- await setItem(key, cacheData);
68
+ await Cache.setItem(key, cacheData);
69
69
  }
70
70
 
71
71
  return cacheData;
@@ -6,7 +6,7 @@ import { Translations, Lang } from '@util/Languages';
6
6
  import type { Page, MarkdownInstance } from 'astro';
7
7
  import { SITE, Frontmatter } from '@config';
8
8
  import { getPageLinks } from '@util/PageLinks';
9
- import { isListable, sortByPubDateDesc, getItem, setItem } from 'astro-accelerator-utils';
9
+ import { Cache, PostFiltering, PostOrdering } from 'astro-accelerator-utils';
10
10
  import Default from 'src/layouts/Default.astro';
11
11
  import ArticleList from '@components/ArticleList.astro';
12
12
  import Paging from '@components/Paging.astro';
@@ -45,7 +45,7 @@ type CacheData = {
45
45
  export async function getCacheData() {
46
46
  const key = 'pages_articles_[category]_[page]';
47
47
 
48
- let cacheData: CacheData = await getItem(key);
48
+ let cacheData: CacheData = await Cache.getItem(key);
49
49
 
50
50
  if (cacheData == null) {
51
51
  // This uses a relative glob, so we only look in the current collection
@@ -54,8 +54,8 @@ export async function getCacheData() {
54
54
  cacheData = { posts: [], categories: []};
55
55
 
56
56
  cacheData.posts = sourcePosts
57
- .filter(isListable)
58
- .sort(sortByPubDateDesc);
57
+ .filter(PostFiltering.isListable)
58
+ .sort(PostOrdering.sortByPubDateDesc);
59
59
 
60
60
  cacheData.posts.forEach(p => {
61
61
  const auths: string[] = p.frontmatter.categories ?? [];
@@ -69,7 +69,7 @@ export async function getCacheData() {
69
69
  });
70
70
  });
71
71
 
72
- await setItem(key, cacheData);
72
+ await Cache.setItem(key, cacheData);
73
73
  }
74
74
 
75
75
  return cacheData;
@@ -1,12 +1,12 @@
1
1
  ---
2
- import { sortByPubDateDesc, getPages } from 'astro-accelerator-utils';
2
+ import { PostQueries, PostOrdering } from 'astro-accelerator-utils';
3
3
  import { fetchPages } from '@util/PageQueries';
4
4
 
5
5
  // Logic
6
- const allPages = await getPages(fetchPages);
6
+ const allPages = await PostQueries.getPages(fetchPages);
7
7
  const missingBanner = allPages.filter(p => p.frontmatter.bannerImage == null && p.frontmatter.layout != 'src/layouts/Redirect.astro');
8
8
  const pageCount = missingBanner.length;
9
- const pages = missingBanner.sort(sortByPubDateDesc).slice(0, Math.min(50, pageCount));
9
+ const pages = missingBanner.sort(PostOrdering.sortByPubDateDesc).slice(0, Math.min(50, pageCount));
10
10
  ---
11
11
  <!doctype html>
12
12
  <html>
@@ -1,12 +1,12 @@
1
1
  ---
2
- import { sortByPubDateDesc, getPages } from 'astro-accelerator-utils';
2
+ import { PostQueries, PostOrdering } from 'astro-accelerator-utils';
3
3
  import { fetchPages } from '@util/PageQueries';
4
4
 
5
5
  // Logic
6
- const allPages = await getPages(fetchPages);
6
+ const allPages = await PostQueries.getPages(fetchPages);
7
7
  const missingMeta = allPages.filter(p => (p.frontmatter.keywords == null || p.frontmatter.description == null) && p.frontmatter.layout != 'src/layouts/Redirect.astro');
8
8
  const pageCount = missingMeta.length;
9
- const pages = missingMeta.sort(sortByPubDateDesc).slice(0, Math.min(50, pageCount));
9
+ const pages = missingMeta.sort(PostOrdering.sortByPubDateDesc).slice(0, Math.min(50, pageCount));
10
10
  ---
11
11
  <!doctype html>
12
12
  <html>
@@ -1,9 +1,9 @@
1
1
  ---
2
- import { getPages } from 'astro-accelerator-utils';
2
+ import { PostQueries } from 'astro-accelerator-utils';
3
3
  import { fetchPages } from '@util/PageQueries';
4
4
 
5
5
  // Logic
6
- const allPages = await getPages(fetchPages);
6
+ const allPages = await PostQueries.getPages(fetchPages);
7
7
  const missingMeta = allPages.filter(p => (p.frontmatter.pubDate == null && p.frontmatter.layout != 'src/layouts/Redirect.astro'));
8
8
  const pageCount = missingMeta.length;
9
9
  const pages = missingMeta.slice(0, Math.min(50, pageCount));
@@ -1,11 +1,11 @@
1
1
  ---
2
- import { sortByModDate, getPages } from 'astro-accelerator-utils';
2
+ import { PostQueries, PostOrdering } from 'astro-accelerator-utils';
3
3
  import { fetchPages } from '@util/PageQueries';
4
4
 
5
5
  // Logic
6
- const allPages = await getPages(fetchPages);
6
+ const allPages = await PostQueries.getPages(fetchPages);
7
7
  const pageCount = allPages.length;
8
- const pages = allPages.sort(sortByModDate).slice(0, Math.min(50, pageCount));
8
+ const pages = allPages.sort(PostOrdering.sortByModDate).slice(0, Math.min(50, pageCount));
9
9
  ---
10
10
  <!doctype html>
11
11
  <html>
@@ -2,7 +2,7 @@
2
2
 
3
3
  import type { MarkdownInstance } from 'astro';
4
4
  import { SITE } from '@config';
5
- import { addSlashToAddress, showInSearch } from 'astro-accelerator-utils';
5
+ import { PostFiltering, Urls } from 'astro-accelerator-utils';
6
6
  import { getTextFrom } from '@util/Markdown';
7
7
 
8
8
  const getData = async () => {
@@ -13,7 +13,7 @@ const getData = async () => {
13
13
  for (const path in allPages) {
14
14
  const page = await allPages[path]() as MarkdownInstance<Record<string, any>>;
15
15
 
16
- if (!showInSearch(page)) {
16
+ if (!PostFiltering.showInSearch(page)) {
17
17
  continue;
18
18
  }
19
19
 
@@ -33,7 +33,7 @@ const getData = async () => {
33
33
  }),
34
34
  description: page.frontmatter.description ?? '',
35
35
  tags: page.frontmatter.tags ?? [],
36
- url: SITE.url + addSlashToAddress(url, SITE),
36
+ url: SITE.url + Urls.addSlashToAddress(url, SITE),
37
37
  date: page.frontmatter.pubDate ?? ''
38
38
  });
39
39
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  // Generates an ATOM feed of recent posts
4
4
  import { SITE } from '@config';
5
- import { addSlashToAddress, showInSitemap } from 'astro-accelerator-utils';
5
+ import { PostFiltering, Urls } from 'astro-accelerator-utils';
6
6
 
7
7
  async function getData() {
8
8
  //@ts-ignore
@@ -12,12 +12,12 @@ async function getData() {
12
12
 
13
13
  for (const path in allPages) {
14
14
  const article: any = await allPages[path]();
15
- const addToSitemap = showInSitemap(article);
15
+ const addToSitemap = PostFiltering.showInSitemap(article);
16
16
 
17
17
  if (addToSitemap) {
18
18
  pages.push(`
19
19
  <url>
20
- <loc>${ SITE.url + addSlashToAddress(article.url, SITE) }</loc>
20
+ <loc>${ SITE.url + Urls.addSlashToAddress(article.url, SITE) }</loc>
21
21
  <lastmod>${ article.frontmatter.pubDate }</lastmod>
22
22
  </url>`);
23
23
  }
@@ -6,7 +6,7 @@ import { Translations, Lang } from '@util/Languages';
6
6
  import type { Page, MarkdownInstance } from 'astro';
7
7
  import { SITE, Frontmatter } from '@config';
8
8
  import { getPageLinks } from '@util/PageLinks';
9
- import { isListable, sortByPubDateDesc, getItem, setItem } from 'astro-accelerator-utils';
9
+ import {Cache, PostFiltering, PostOrdering } from 'astro-accelerator-utils';
10
10
  import Default from 'src/layouts/Default.astro';
11
11
  import ArticleList from '@components/ArticleList.astro';
12
12
  import Paging from '@components/Paging.astro';
@@ -45,7 +45,7 @@ type CacheData = {
45
45
  export async function getCacheData() {
46
46
  const key = 'pages_articles_[tag]_[page]';
47
47
 
48
- let cacheData: CacheData = await getItem(key);
48
+ let cacheData: CacheData = await Cache.getItem(key);
49
49
 
50
50
  if (cacheData == null) {
51
51
  // This uses a relative glob, so we only look in the current collection
@@ -54,8 +54,8 @@ export async function getCacheData() {
54
54
  cacheData = { posts: [], tags: []};
55
55
 
56
56
  cacheData.posts = sourcePosts
57
- .filter(isListable)
58
- .sort(sortByPubDateDesc);
57
+ .filter(PostFiltering.isListable)
58
+ .sort(PostOrdering.sortByPubDateDesc);
59
59
 
60
60
  cacheData.posts.forEach(p => {
61
61
  const auths: string[] = p.frontmatter.tags ?? [];
@@ -69,7 +69,7 @@ export async function getCacheData() {
69
69
  });
70
70
  });
71
71
 
72
- await setItem(key, cacheData);
72
+ await Cache.setItem(key, cacheData);
73
73
  }
74
74
 
75
75
  return cacheData;
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  import type { MarkdownInstance } from 'astro';
3
+ import { Urls } from 'astro-accelerator-utils';
3
4
  import { SITE, Frontmatter } from '@config';
4
- import { addSlashToAddress } from 'astro-accelerator-utils';
5
5
  import { getImageInfo } from '@util/custom-markdown.mjs';
6
6
  import { getTextFrom } from '@util/Markdown';
7
7
  import AuthorsMini from '@components/AuthorsMini.astro';
@@ -55,7 +55,7 @@ function getLoadingAttribute() {
55
55
  ---
56
56
  <ul class="post-list anim-show-parent">
57
57
  {articles.map((post) => (
58
- <li class="list-item" data-destination={ addSlashToAddress(post.url, SITE) } data-image={ (post.frontmatter.bannerImage?.src.length > 0).toString() }>
58
+ <li class="list-item" data-destination={ Urls.addSlashToAddress(post.url, SITE) } data-image={ (post.frontmatter.bannerImage?.src.length > 0).toString() }>
59
59
  <article>
60
60
  <div class="list-item-image">
61
61
  {post.img && (
@@ -70,7 +70,7 @@ function getLoadingAttribute() {
70
70
  </div>
71
71
  <div class="list-item-content">
72
72
  <h3>
73
- <a href={ addSlashToAddress(post.url, SITE) }>{ post.frontmatter.title }</a>
73
+ <a href={ Urls.addSlashToAddress(post.url, SITE) }>{ post.frontmatter.title }</a>
74
74
  </h3>
75
75
  <AuthorsMini lang={ lang } frontmatter={ post.frontmatter as Frontmatter } />
76
76
  </div>
@@ -1,7 +1,7 @@
1
1
  ---
2
+ import { Dates, Urls } from 'astro-accelerator-utils';
2
3
  import { SITE, Frontmatter } from '@config';
3
4
  import { Translations, Lang } from '@util/Languages';
4
- import { formatDate, formatModifiedDate, addSlashToAddress } from 'astro-accelerator-utils';
5
5
  import { getAuthorList } from '@util/Authors';
6
6
  import { getImageInfo } from '@util/custom-markdown.mjs';
7
7
 
@@ -35,16 +35,16 @@ const contributors = authorList.writers.slice(1);
35
35
  <div class="author-info">
36
36
  <span>{ _(Translations.post.written_by) }
37
37
  {author &&
38
- <a href={ addSlashToAddress(author.url, SITE) + '1/' } itemprop="author">{ author.frontmatter.title }</a>
38
+ <a href={ Urls.addSlashToAddress(author.url, SITE) + '1/' } itemprop="author">{ author.frontmatter.title }</a>
39
39
  }{contributors.map((writer) => (
40
- <a href={ addSlashToAddress(writer.url, SITE) + '1/' } itemprop="contributor">{ writer.frontmatter.title }</a>
40
+ <a href={ Urls.addSlashToAddress(writer.url, SITE) + '1/' } itemprop="contributor">{ writer.frontmatter.title }</a>
41
41
  ))}.
42
42
  <br /><time datetime={ frontmatter.pubDate.toString() } itemprop="datePublished">
43
- { formatDate(frontmatter, lang, SITE) }
43
+ { Dates.formatDate(frontmatter, lang, SITE) }
44
44
  </time>
45
45
  {frontmatter.modDate &&
46
46
  <br /><time datetime={ frontmatter.modDate.toString() } itemprop="dateModified">
47
- { _(Translations.post.last_modified) } { formatModifiedDate(frontmatter, lang, SITE) }
47
+ { _(Translations.post.last_modified) } { Dates.formatModifiedDate(frontmatter, lang, SITE) }
48
48
  </time>
49
49
  }
50
50
  </span>
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  import { SITE, Frontmatter } from '@config';
3
3
  import { Translations, Lang } from '@util/Languages';;
4
- import { formatDate } from 'astro-accelerator-utils';
4
+ import { Dates } from 'astro-accelerator-utils';
5
5
  import { getAuthorList } from '@util/Authors';
6
6
 
7
7
  // Properties
@@ -25,9 +25,9 @@ const authorList = await getAuthorList(frontmatter);
25
25
  <span>{ writer.frontmatter.title }</span>
26
26
  ))}.<br />
27
27
  <time datetime={ frontmatter.pubDate.toString() }>
28
- { formatDate(frontmatter, lang, SITE) }
28
+ { Dates.formatDate(frontmatter, lang, SITE) }
29
29
  </time>
30
30
  </span>
31
31
  </div>
32
32
  </div>
33
- }
33
+ }
@@ -1,8 +1,8 @@
1
1
  ---
2
+ import { Urls } from 'astro-accelerator-utils';
2
3
  import { SITE, Frontmatter } from '@config';
3
4
  import { Translations, Lang } from '@util/Languages';
4
5
  import { getBreadcrumbs } from '@util/Breadcrumbs';
5
- import { addSlashToAddress } from 'astro-accelerator-utils';
6
6
 
7
7
  // Properties
8
8
  type Props = {
@@ -24,7 +24,7 @@ const navPages = await getBreadcrumbs(currentUrl);
24
24
  {navPages.map((page, index) => (
25
25
  <li property="itemListElement" typeof="ListItem">
26
26
  <meta property="position" content={ index.toString() } />
27
- <a property="item" typeof="WebPage" href={ addSlashToAddress(page.url, SITE) } aria-current={ page.ariaCurrent } rel={ page.rel }><span property="name">{ page.title }</span></a>
27
+ <a property="item" typeof="WebPage" href={ Urls.addSlashToAddress(page.url, SITE) } aria-current={ page.ariaCurrent } rel={ page.rel }><span property="name">{ page.title }</span></a>
28
28
  </li>
29
29
  ))}
30
30
  </ol>
@@ -1,8 +1,8 @@
1
1
  ---
2
+ import { Urls, PostQueries, PostFiltering } from 'astro-accelerator-utils';
2
3
  import { SITE, Frontmatter } from '@config';
3
4
  import { Translations, Lang } from '@util/Languages';
4
5
  import { fetchPages } from '@util/PageQueries';
5
- import { addSlashToAddress, isSearch, getPages } from 'astro-accelerator-utils';
6
6
 
7
7
  // Properties
8
8
  type Props = {
@@ -16,7 +16,7 @@ const { lang } = Astro.props as Props;
16
16
  const _ = Lang(lang);
17
17
 
18
18
  // Logic
19
- const search = (await getPages(fetchPages, isSearch))[0] ?? null;
19
+ const search = (await PostQueries.getPages(fetchPages, PostFiltering.isSearch))[0] ?? null;
20
20
 
21
21
  ---
22
22
  <header class="site-header">
@@ -30,7 +30,7 @@ const search = (await getPages(fetchPages, isSearch))[0] ?? null;
30
30
  </svg></a>
31
31
  <a href={ (SITE.subfolder ?? '') + '/' } class="site-title" translate="no">{ SITE.title }</a>
32
32
  {search != null &&
33
- <a href={ addSlashToAddress(search.url, SITE) } class="search-icon" title={ _(Translations.header.open_search) }><svg xmlns="http://www.w3.org/2000/svg"
33
+ <a href={ Urls.addSlashToAddress(search.url, SITE) } class="search-icon" title={ _(Translations.header.open_search) }><svg xmlns="http://www.w3.org/2000/svg"
34
34
  width="40" height="40" viewBox="0 0 24 24" stroke-width="1"
35
35
  fill="none" stroke-linecap="round" stroke-linejoin="round">
36
36
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
@@ -1,6 +1,6 @@
1
1
  ---
2
+ import { Urls } from 'astro-accelerator-utils';
2
3
  import { SITE, OPEN_GRAPH, HEADER_SCRIPTS, Frontmatter } from '@config';
3
- import { addSlashToUrl } from 'astro-accelerator-utils';
4
4
  import { getTextFrom } from '@util/Markdown';
5
5
 
6
6
  // Properties
@@ -16,7 +16,7 @@ const imageSrc = frontmatter.bannerImage?.src ?? OPEN_GRAPH.image.src;
16
16
  const imageAlt = frontmatter.bannerImage?.alt ?? OPEN_GRAPH.image.alt;
17
17
  const robots = frontmatter.robots ?? 'index, follow';
18
18
  const canonicalImageSrc = new URL(imageSrc, Astro.site);
19
- const canonicalURL = addSlashToUrl(new URL(Astro.url.pathname, Astro.site + SITE.subfolder));
19
+ const canonicalURL = Urls.addSlashToUrl(new URL(Astro.url.pathname, Astro.site + SITE.subfolder));
20
20
  const title = await getTextFrom( frontmatter.title ? `${ frontmatter.title } | ${ SITE.title }` : SITE.title);
21
21
  ---
22
22
  <head>
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  import { SITE } from '@config';
3
3
  import type { NavPage } from '@util/NavigationTypes';
4
- import { addSlashToAddress } from 'astro-accelerator-utils';
4
+ import { Urls } from 'astro-accelerator-utils';
5
5
 
6
6
  // Properties
7
7
  type Props = {
@@ -12,7 +12,7 @@ const { lang, page } = Astro.props as Props;
12
12
  ---
13
13
  {(page.children.length == 0) && (
14
14
  <li>
15
- <a href={ addSlashToAddress(page.url, SITE) } aria-current={ page.ariaCurrent } rel={ page.rel }>{ page.title }</a>
15
+ <a href={ Urls.addSlashToAddress(page.url, SITE) } aria-current={ page.ariaCurrent } rel={ page.rel }>{ page.title }</a>
16
16
  </li>
17
17
  )}
18
18
  {(page.children.length > 0) && (
@@ -1,9 +1,9 @@
1
1
  ---
2
+ import { Urls } from 'astro-accelerator-utils';
2
3
  import { SITE } from '@config';
3
4
  import type { Link } from '@util/PageLinks';
4
5
  import type { MarkdownInstance, Page } from 'astro';
5
6
  import { Translations, Lang } from '@util/Languages';
6
- import { addSlashToAddress } from 'astro-accelerator-utils';
7
7
 
8
8
  // Properties
9
9
  type Props = {
@@ -21,12 +21,12 @@ const _ = Lang(lang);
21
21
  ---
22
22
  <nav class="post-paging" aria-label={ _(Translations.aria.paging) }>
23
23
  {page.url.prev
24
- ? <a href={ addSlashToAddress(page.url.prev, SITE) }>{ _(Translations.articles.previous) }</a>
24
+ ? <a href={ Urls.addSlashToAddress(page.url.prev, SITE) }>{ _(Translations.articles.previous) }</a>
25
25
  : <span>{ _(Translations.articles.previous) }</span>}
26
26
  {pageLinks.map((link) => (
27
- <a href={ addSlashToAddress(link.url, SITE) } aria-current={ link.ariaCurrent } class={ link.class }>{ link.title }</a>
27
+ <a href={ Urls.addSlashToAddress(link.url, SITE) } aria-current={ link.ariaCurrent } class={ link.class }>{ link.title }</a>
28
28
  ))}
29
29
  {page.url.next
30
- ? <a href={ addSlashToAddress(page.url.next, SITE) }>{ _(Translations.articles.next) }</a>
30
+ ? <a href={ Urls.addSlashToAddress(page.url.next, SITE) }>{ _(Translations.articles.next) }</a>
31
31
  : <span>{ _(Translations.articles.next) }</span>}
32
32
  </nav>
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  import { SITE, Frontmatter } from '@config';
3
3
  import type { MarkdownInstance } from 'astro';
4
- import { addSlashToAddress, isListable, sortByPubDateDesc, getPages } from 'astro-accelerator-utils';
4
+ import { Urls, PostQueries, PostFiltering, PostOrdering } from 'astro-accelerator-utils';
5
5
  import { getImageInfo } from '@util/custom-markdown.mjs'
6
6
  import { fetchPages } from '@util/PageQueries';
7
7
 
@@ -20,10 +20,10 @@ let posts: MarkdownInstance<Record<string, any>>[] = [];
20
20
  const parentCagory = (frontmatter.categories ?? [null])[0];
21
21
 
22
22
  if (parentCagory != null) {
23
- const allPages = await getPages(fetchPages, isListable)
23
+ const allPages = await PostQueries.getPages(fetchPages, PostFiltering.isListable)
24
24
  const allPosts = allPages
25
25
  .filter(p => p.frontmatter.title != frontmatter.title && p.frontmatter.categories && p.frontmatter.categories.includes(parentCagory))
26
- .sort(sortByPubDateDesc)
26
+ .sort(PostOrdering.sortByPubDateDesc)
27
27
 
28
28
  // One "Most Recent" Post
29
29
  if (allPosts.length > 0) {
@@ -53,7 +53,7 @@ const articles = posts.map(p => {
53
53
  {articles.length > 0 &&
54
54
  <ul class="post-list anim-show-parent">
55
55
  {articles.map((post) => (
56
- <li class="list-item" data-destination={ addSlashToAddress(post.url, SITE) } data-image={ (post.frontmatter.bannerImage?.src.length > 0).toString() }>
56
+ <li class="list-item" data-destination={ Urls.addSlashToAddress(post.url, SITE) } data-image={ (post.frontmatter.bannerImage?.src.length > 0).toString() }>
57
57
  <article>
58
58
  <div class="list-item-image">
59
59
  {post.img && (
@@ -68,7 +68,7 @@ const articles = posts.map(p => {
68
68
  </div>
69
69
  <div class="list-item-content">
70
70
  <h3>
71
- <a href={ addSlashToAddress(post.url, SITE) }>{ post.frontmatter.title }</a>
71
+ <a href={ Urls.addSlashToAddress(post.url, SITE) }>{ post.frontmatter.title }</a>
72
72
  </h3>
73
73
  <AuthorsMini lang={ lang } frontmatter={ post.frontmatter as Frontmatter } />
74
74
  </div>
@@ -1,6 +1,6 @@
1
1
  ---
2
+ import { PostQueries } from 'astro-accelerator-utils';
2
3
  import { SITE, Frontmatter } from '@config';
3
- import { getPages } from 'astro-accelerator-utils';
4
4
  import { Translations, Lang } from '@util/Languages';
5
5
  import { fetchPages } from '@util/PageQueries';
6
6
  import Default from './Default.astro';
@@ -18,7 +18,7 @@ const lang = frontmatter.lang ?? SITE.default.lang;
18
18
  const _ = Lang(lang);
19
19
 
20
20
  // Logic
21
- const authorPages = await getPages(fetchPages, p => p.frontmatter.authors?.indexOf(frontmatter.id) > -1)
21
+ const authorPages = await PostQueries.getPages(fetchPages, p => p.frontmatter.authors?.indexOf(frontmatter.id) > -1)
22
22
  ---
23
23
  <Default frontmatter={ frontmatter } headings={ headings }>
24
24
  <slot />
@@ -1,8 +1,7 @@
1
- import type { Frontmatter } from '@config';
2
1
  import type { MarkdownInstance } from 'astro';
3
-
2
+ import { PostQueries, PostFiltering } from "astro-accelerator-utils";
3
+ import type { Frontmatter } from '@config';
4
4
  import { fetchPages } from "@util/PageQueries";
5
- import { isAuthor, getPages } from "astro-accelerator-utils";
6
5
 
7
6
  type BannerImage = { src: string; alt: string } | null;
8
7
  type AuthorList = {
@@ -11,7 +10,7 @@ type AuthorList = {
11
10
  };
12
11
 
13
12
  export async function getAuthors () {
14
- const authors = await getPages(fetchPages, isAuthor);
13
+ const authors = await PostQueries.getPages(fetchPages, PostFiltering.isAuthor);
15
14
  return authors;
16
15
  }
17
16
 
@@ -1,11 +1,11 @@
1
- import { getPages } from 'astro-accelerator-utils';
1
+ import { PostQueries } from 'astro-accelerator-utils';
2
2
  import { fetchPages } from '@util/PageQueries';
3
3
  import { mapNavPage, setCurrentPage, popMatchingPage } from '@util/NavPage';
4
4
 
5
5
  import type { NavPage } from '@util/NavigationTypes';
6
6
 
7
7
  export async function getBreadcrumbs (currentUrl: URL) {
8
- const allPages = await getPages(fetchPages);
8
+ const allPages = await PostQueries.getPages(fetchPages);
9
9
 
10
10
  const pathParts = currentUrl.pathname.split('/');
11
11
  const navPages: NavPage[] = [];
@@ -1,18 +1,17 @@
1
1
  // Data file `navigation.ts`
2
+ import { Cache } from 'astro-accelerator-utils';
2
3
  import { menu } from 'src/data/footer';
3
- import { Translations, Lang } from '@util/Languages';
4
+ import { Translations, Lang, TranslationProvider } from '@util/Languages';
4
5
  import { SITE } from '@config';
5
- import { getItem, setItem } from 'astro-accelerator-utils';
6
6
  import { setCurrentPage } from '@util/NavPage';
7
7
  import { NavPage, isNavPage } from '@util/NavigationTypes';
8
- import { getTaxonomy, taxonomyLinks } from '@util/Taxonomy';
9
-
8
+ import { getTaxonomy, taxonomyLinks, TaxonomyLinks } from '@util/Taxonomy';
10
9
 
11
10
  export async function getMenu (currentUrl: URL, lang: string) {
12
11
  const key = 'Footer__getMenu_' + lang;
13
12
  const _ = Lang(lang);
14
13
  const links = taxonomyLinks(_);
15
- let pages: NavPage[] = await getItem(key);
14
+ let pages: NavPage[] = await Cache.getItem(key);
16
15
 
17
16
  if (pages == null) {
18
17
  pages = [];
@@ -45,7 +44,7 @@ export async function getMenu (currentUrl: URL, lang: string) {
45
44
  }
46
45
 
47
46
  // Cache the result
48
- await setItem(key, pages);
47
+ await Cache.setItem(key, pages);
49
48
  }
50
49
 
51
50
  setCurrentPage(pages, currentUrl);
@@ -53,10 +52,10 @@ export async function getMenu (currentUrl: URL, lang: string) {
53
52
  return pages;
54
53
  }
55
54
 
56
- export async function getCategories (links, _, lang: string) {
55
+ export async function getCategories (links: TaxonomyLinks, _: TranslationProvider, lang: string) {
57
56
 
58
57
  const key = 'Footer__getCategories_' + lang;
59
- let pageHierarchy: NavPage[] = await getItem(key);
58
+ let pageHierarchy: NavPage[] = await Cache.getItem(key);
60
59
 
61
60
  if (pageHierarchy == null) {
62
61
  const category = _(Translations.articles.category) ?? 'category';
@@ -86,16 +85,16 @@ export async function getCategories (links, _, lang: string) {
86
85
  }];
87
86
 
88
87
  // Cache the result
89
- await setItem(key, pageHierarchy);
88
+ await Cache.setItem(key, pageHierarchy);
90
89
  }
91
90
 
92
91
  return pageHierarchy;
93
92
  }
94
93
 
95
- export async function getTags (links, _, lang: string) {
94
+ export async function getTags (links: TaxonomyLinks, _: TranslationProvider, lang: string) {
96
95
 
97
96
  const key = 'Footer__getTags_' + lang;
98
- let pageHierarchy: NavPage[] = await getItem(key);
97
+ let pageHierarchy: NavPage[] = await Cache.getItem(key);
99
98
 
100
99
  if (pageHierarchy == null) {
101
100
  const _ = Lang(lang);
@@ -126,16 +125,16 @@ export async function getTags (links, _, lang: string) {
126
125
  }];
127
126
 
128
127
  // Cache the result
129
- await setItem(key, pageHierarchy);
128
+ await Cache.setItem(key, pageHierarchy);
130
129
  }
131
130
 
132
131
  return pageHierarchy;
133
132
  }
134
133
 
135
- export async function getTopTags (links, _, lang: string) {
134
+ export async function getTopTags (links: TaxonomyLinks, _: TranslationProvider, lang: string) {
136
135
 
137
136
  const key = 'Footer__getTopTags_' + lang;
138
- let pageHierarchy: NavPage[] = await getItem(key);
137
+ let pageHierarchy: NavPage[] = await Cache.getItem(key);
139
138
 
140
139
  if (pageHierarchy == null) {
141
140
  const _ = Lang(lang);
@@ -166,7 +165,7 @@ if (pageHierarchy == null) {
166
165
  }];
167
166
 
168
167
  // Cache the result
169
- await setItem(key, pageHierarchy);
168
+ await Cache.setItem(key, pageHierarchy);
170
169
  }
171
170
 
172
171
  return pageHierarchy;
@@ -3,7 +3,11 @@ import user from '@data/language.json';
3
3
 
4
4
  export const Translations = {...bundled, ...user};
5
5
 
6
- export function Lang (lang: string): (entry: Entry) => string {
6
+ export type TranslationProvider = {
7
+ (entry: Entry): string;
8
+ }
9
+
10
+ export function Lang (lang: string): TranslationProvider {
7
11
  const altLang = lang.indexOf('-') > -1
8
12
  ? lang.split('-')[0]
9
13
  : lang;
@@ -2,7 +2,7 @@ import { SITE } from '@config';
2
2
  import type { MarkdownInstance } from 'astro';
3
3
  import type { NavPage } from './NavigationTypes';
4
4
 
5
- import { addSlashToAddress } from 'astro-accelerator-utils';
5
+ import { Urls } from 'astro-accelerator-utils';
6
6
 
7
7
  export function mapNavPage (page: MarkdownInstance<Record<string, any>>) {
8
8
 
@@ -15,7 +15,7 @@ export function mapNavPage (page: MarkdownInstance<Record<string, any>>) {
15
15
  url += '/1/';
16
16
  }
17
17
 
18
- url = addSlashToAddress(url, SITE);
18
+ url = Urls.addSlashToAddress(url, SITE);
19
19
 
20
20
  if (page.frontmatter.layout == 'src/layouts/Redirect.astro') {
21
21
  // Skips past the redirect
@@ -1,14 +1,14 @@
1
1
  // Data file `navigation.ts`
2
2
  import { menu } from 'src/data/navigation';
3
3
 
4
- import { showInMenu, getItem, setItem, getPages } from 'astro-accelerator-utils';
4
+ import { PostQueries, PostFiltering, Cache } from 'astro-accelerator-utils';
5
5
  import { mapNavPage, setCurrentPage } from '@util/NavPage';
6
6
  import { NavPage, isNavPage } from '@util/NavigationTypes';
7
7
  import { getTopLevelPages, fetchPages } from '@util/PageQueries';
8
8
 
9
9
  export async function getMenu (currentUrl: URL) {
10
10
  const key = 'Navigation__getMenu';
11
- let pages: NavPage[] = await getItem(key);
11
+ let pages: NavPage[] = await Cache.getItem(key);
12
12
 
13
13
  if (pages == null) {
14
14
  pages = [];
@@ -25,7 +25,7 @@ export async function getMenu (currentUrl: URL) {
25
25
  }
26
26
 
27
27
  // Cache the result
28
- await setItem(key, pages);
28
+ await Cache.setItem(key, pages);
29
29
  }
30
30
 
31
31
  setCurrentPage(pages, currentUrl);
@@ -36,11 +36,11 @@ export async function getMenu (currentUrl: URL) {
36
36
  export async function getNavigation (currentUrl: URL) {
37
37
 
38
38
  const key = 'Navigation__getNavigation';
39
- let pageHierarchy: NavPage[] = await getItem(key);
39
+ let pageHierarchy: NavPage[] = await Cache.getItem(key);
40
40
 
41
41
  if (pageHierarchy == null) {
42
- const topLevelPages = await getTopLevelPages(showInMenu);
43
- const allPages = await getPages(fetchPages, showInMenu);
42
+ const topLevelPages = await getTopLevelPages(PostFiltering.showInMenu);
43
+ const allPages = await PostQueries.getPages(fetchPages, PostFiltering.showInMenu);
44
44
 
45
45
  pageHierarchy = topLevelPages
46
46
  .map(mapNavPage)
@@ -71,7 +71,7 @@ export async function getNavigation (currentUrl: URL) {
71
71
  }
72
72
 
73
73
  // Cache the result
74
- await setItem(key, pageHierarchy);
74
+ await Cache.setItem(key, pageHierarchy);
75
75
  }
76
76
 
77
77
  return pageHierarchy;
@@ -1,36 +1,19 @@
1
1
  import type { MarkdownInstance } from "astro";
2
2
  import { SITE } from '@config';
3
- import { isAuthor, getItem, setItem, PagePredicate, getPages } from 'astro-accelerator-utils';
3
+ import { Cache, PostQueries, PostFiltering } from 'astro-accelerator-utils';
4
4
 
5
5
  export function fetchPages(): Record<string, any> {
6
6
  return import.meta.glob("../../../pages/**/*.md", { eager: true });
7
7
  }
8
8
 
9
- // export type PagePredicate = (value: MarkdownInstance<Record<string, any>>, index: number, array: MarkdownInstance<Record<string, any>>[]) => boolean;
10
-
11
- // export async function getPages (fetchPages: () => Record<string, any>, filter?: PagePredicate | null): Promise<MarkdownInstance<Record<string,any>>[]> {
12
- // const key = 'PageQueries__getPages';
13
- // let allPages: MarkdownInstance<Record<string,any>>[] = await getItem(key);
14
-
15
- // if (allPages == null) {
16
- // const pageImportResult = fetchPages();
17
- // allPages = Object.values(pageImportResult) as MarkdownInstance<Record<string,any>>[];
18
- // await setItem(key, allPages);
19
- // }
20
-
21
- // if (filter == null) {
22
- // return allPages;
23
- // }
24
-
25
- // return allPages.filter(filter);
26
- // }
9
+ export type PagePredicate = (value: MarkdownInstance<Record<string, any>>, index: number, array: MarkdownInstance<Record<string, any>>[]) => boolean;
27
10
 
28
11
  export async function getTopLevelPages (filter?: PagePredicate | null): Promise<MarkdownInstance<Record<string,any>>[]> {
29
12
  const key = 'PageQueries__getTopLevelPages';
30
- let allPages = await getItem(key);
13
+ let allPages: MarkdownInstance<Record<string, any>>[] = await Cache.getItem(key);
31
14
 
32
15
  if (allPages == null) {
33
- allPages = await getPages(fetchPages);
16
+ allPages = await PostQueries.getPages(fetchPages);
34
17
 
35
18
  const isRoot = SITE.subfolder.length == 0;
36
19
  const expectedDepth = isRoot ? 1 : 2;
@@ -40,7 +23,7 @@ export async function getTopLevelPages (filter?: PagePredicate | null): Promise<
40
23
  || (depth == (expectedDepth - 1) && p.file.includes(SITE.subfolder.toLowerCase() + '.md'));
41
24
  });
42
25
 
43
- await setItem(key, allPages);
26
+ await Cache.setItem(key, allPages);
44
27
  }
45
28
 
46
29
  if (filter == null) {
@@ -53,20 +36,20 @@ export async function getTopLevelPages (filter?: PagePredicate | null): Promise<
53
36
  export async function getAuthorInfo (slug: string) {
54
37
  const cacheKey = 'Global__author_info';
55
38
 
56
- let authorInfo = await getItem(cacheKey);
39
+ let authorInfo = await Cache.getItem(cacheKey);
57
40
 
58
41
  if (authorInfo == null) {
59
- const allPages = await getPages(fetchPages);
42
+ const allPages = await PostQueries.getPages(fetchPages);
60
43
 
61
44
  const author = allPages
62
- .filter(isAuthor)
45
+ .filter(PostFiltering.isAuthor)
63
46
  .filter(x => x.url?.split('/')[2] == slug)[0];
64
47
 
65
48
  authorInfo = {
66
49
  frontmatter: author.frontmatter
67
50
  };
68
51
 
69
- await setItem(cacheKey, authorInfo);
52
+ await Cache.setItem(cacheKey, authorInfo);
70
53
  }
71
54
 
72
55
  return authorInfo;
@@ -1,8 +1,9 @@
1
+ import { Cache, Urls, PostQueries } from 'astro-accelerator-utils';
1
2
  import type { Entry } from '@util/Languages';
2
3
  import { Translations } from '@util/Languages';
3
4
  import { SITE } from '@config';
4
5
  import { fetchPages } from '@util/PageQueries';
5
- import { addSlashToAddress, getItem, setItem, getPages } from 'astro-accelerator-utils';
6
+ import type { MarkdownInstance } from 'astro-accelerator-utils/types/Astro';
6
7
 
7
8
  type TaxonomyEntry = {
8
9
  title: string;
@@ -27,7 +28,14 @@ export function sortByTitle (a: TaxonomyEntry, b: TaxonomyEntry) {
27
28
  return 0;
28
29
  }
29
30
 
30
- export function taxonomyLinks(lang: (entry: Entry) => string) {
31
+ export type TaxonomyLinks = {
32
+ tag: string;
33
+ category: string;
34
+ getCategoryLink: (category: string) => string;
35
+ getTagLink: (tag: string) => string;
36
+ }
37
+
38
+ export function taxonomyLinks(lang: (entry: Entry) => string): TaxonomyLinks {
31
39
  const category = lang(Translations.articles.category) ?? 'category';
32
40
  const categoryLink = `${SITE.subfolder}/${category}/`;
33
41
 
@@ -38,10 +46,10 @@ export function taxonomyLinks(lang: (entry: Entry) => string) {
38
46
  tag: tag,
39
47
  category: category,
40
48
  getCategoryLink: (category: string) => {
41
- return addSlashToAddress(categoryLink + category.toLowerCase().replace(/ /g, '-') + '/1/', SITE);
49
+ return Urls.addSlashToAddress(categoryLink + category.toLowerCase().replace(/ /g, '-') + '/1/', SITE);
42
50
  },
43
51
  getTagLink: (tag: string) => {
44
- return addSlashToAddress(tagLink + tag.toLowerCase().replace(/ /g, '-') + '/1/', SITE);
52
+ return Urls.addSlashToAddress(tagLink + tag.toLowerCase().replace(/ /g, '-') + '/1/', SITE);
45
53
  }
46
54
  };
47
55
 
@@ -50,20 +58,20 @@ export function taxonomyLinks(lang: (entry: Entry) => string) {
50
58
  export async function getTaxonomy (): Promise<Taxonomy> {
51
59
  const cacheKey = 'Global__taxonomy';
52
60
 
53
- let taxonomy: Taxonomy = await getItem(cacheKey);
61
+ let taxonomy: Taxonomy = await Cache.getItem(cacheKey);
54
62
 
55
63
  if (taxonomy == null) {
56
- const allPages = await getPages(fetchPages);
64
+ const allPages: MarkdownInstance<Record<string, any>>[] = await PostQueries.getPages(fetchPages);
57
65
  const tags: { [key: string]: number } = {};
58
66
  const cats: { [key: string]: number } = {};
59
67
 
60
68
  // Get taxonomy and counts
61
69
  allPages.forEach((p) => {
62
- p.frontmatter.tags && p.frontmatter.tags.forEach(t => {
70
+ p.frontmatter.tags && (p.frontmatter.tags as string[]).forEach(t => {
63
71
  tags[t] = (tags[t] ?? 0) + 1;
64
72
  });
65
73
 
66
- p.frontmatter.categories && p.frontmatter.categories.forEach(c => {
74
+ p.frontmatter.categories && (p.frontmatter.categories as string[]).forEach(c => {
67
75
  cats[c] = (cats[c] ?? 0) + 1;
68
76
  });
69
77
  });
@@ -100,7 +108,7 @@ export async function getTaxonomy (): Promise<Taxonomy> {
100
108
  return 0;
101
109
  });
102
110
 
103
- await setItem(cacheKey, taxonomy);
111
+ await Cache.setItem(cacheKey, taxonomy);
104
112
  }
105
113
 
106
114
  return taxonomy;
@@ -1,9 +1,10 @@
1
1
  import { SITE } from '/src/config';
2
- import { visit } from 'unist-util-visit';
3
- import { h } from 'hastscript';
4
2
  import { size } from '/src/data/image-size.mjs';
3
+ import { h } from 'hastscript';
4
+ import { visit } from 'unist-util-visit';
5
5
  import { fromSelector } from 'hast-util-from-selector'
6
-
6
+ import path from 'path';
7
+ import fs from 'fs';
7
8
 
8
9
  /* Based on https://github.com/remarkjs/remark-directive
9
10
  * Examples:
@@ -30,6 +31,8 @@ This is a custom div element with the class `note`
30
31
 
31
32
  */
32
33
 
34
+ const workingDirectory = process.cwd();
35
+
33
36
  export function getDestination(uri, s) {
34
37
  const fromRegEx = new RegExp('^' + SITE.subfolder + '/img/');
35
38
  const replacement = SITE.subfolder + '/i/' + s.toString() + '/';
@@ -66,6 +69,13 @@ export function attributeMarkdown() {
66
69
  const hast = h(node.name, node.attributes);
67
70
 
68
71
  if (hast.properties.src) {
72
+ let metadata = null;
73
+ let metaAddress = path.join(workingDirectory, 'public', hast.properties.src + '.json');
74
+
75
+ if (fs.existsSync(metaAddress)) {
76
+ metadata = JSON.parse(fs.readFileSync(metaAddress));
77
+ }
78
+
69
79
  // Process the image
70
80
  const info = getImageInfo(hast.properties.src, hast.properties.class, SITE.images.contentSize);
71
81
 
@@ -73,6 +83,11 @@ export function attributeMarkdown() {
73
83
  hast.properties.srcset = info.srcset;
74
84
  hast.properties.sizes = info.sizes;
75
85
  hast.properties.class = info.class;
86
+
87
+ if (metadata) {
88
+ hast.properties.width = metadata.width;
89
+ hast.properties.height = metadata.height;
90
+ }
76
91
  }
77
92
 
78
93
  data.hName = hast.tagName;
@@ -94,7 +94,7 @@ for (const file of filesToProcess) {
94
94
 
95
95
  const ext = path.parse(source).ext;
96
96
 
97
- let image;
97
+ let image = null;
98
98
  let rawEncodedImage;
99
99
 
100
100
  // Create optimised fallback image
@@ -117,6 +117,19 @@ for (const file of filesToProcess) {
117
117
  await fs.promises.writeFile(destination + '.webp', rawEncodedImage);
118
118
  break;
119
119
  }
120
+
121
+ if (image) {
122
+ const info = await image.decoded;
123
+ const metadata = {
124
+ width: info.bitmap.width,
125
+ height: info.bitmap.height,
126
+ sizeInBytes: info.size
127
+ };
128
+
129
+ const metaFile = source + '.json';
130
+ await fs.promises.writeFile(metaFile, JSON.stringify(metadata));
131
+ }
132
+
120
133
  await imagePool.close();
121
134
 
122
135
  // Create resized images