astro-accelerator 0.0.31 → 0.0.33

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 (30) hide show
  1. package/package.json +2 -2
  2. package/src/config.ts +3 -1
  3. package/src/data/footer.ts +1 -1
  4. package/src/data/navigation.ts +1 -1
  5. package/src/pages/articles/[page].astro +10 -26
  6. package/src/pages/articles/feed.xml.ts +5 -3
  7. package/src/pages/authors/[author]/[page].astro +21 -30
  8. package/src/pages/category/[category]/[page].astro +21 -29
  9. package/src/pages/category/[category]/index.astro +2 -2
  10. package/src/pages/report/missing-banner.astro +4 -2
  11. package/src/pages/report/missing-meta.astro +4 -2
  12. package/src/pages/report/missing-pubdate.astro +4 -2
  13. package/src/pages/report/oldest-content.astro +11 -2
  14. package/src/pages/search.json.ts +6 -3
  15. package/src/pages/sitemap.xml.ts +3 -2
  16. package/src/pages/tag/[tag]/[page].astro +20 -29
  17. package/src/pages/tag/[tag]/index.astro +2 -2
  18. package/src/themes/accelerator/components/ArticleList.astro +15 -7
  19. package/src/themes/accelerator/components/Authors.astro +7 -5
  20. package/src/themes/accelerator/components/AuthorsMini.astro +3 -2
  21. package/src/themes/accelerator/components/Breadcrumbs.astro +3 -2
  22. package/src/themes/accelerator/components/FooterItem.astro +2 -2
  23. package/src/themes/accelerator/components/Header.astro +3 -2
  24. package/src/themes/accelerator/components/HtmlHead.astro +6 -3
  25. package/src/themes/accelerator/components/NavigationItem.astro +6 -3
  26. package/src/themes/accelerator/components/Paging.astro +6 -6
  27. package/src/themes/accelerator/components/Related.astro +4 -3
  28. package/src/themes/accelerator/layouts/Default.astro +5 -2
  29. package/src/themes/accelerator/utilities/custom-markdown.mjs +14 -10
  30. package/src/themes/accelerator/utilities/TempNavPage.ts +0 -10
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.31",
2
+ "version": "0.0.33",
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.44",
29
+ "astro-accelerator-utils": "^0.1.4",
30
30
  "hast-util-from-selector": "^2.0.0",
31
31
  "remark-directive": "^2.0.1"
32
32
  },
package/src/config.ts CHANGED
@@ -1,4 +1,6 @@
1
- const SITE = {
1
+ import type { Site } from "astro-accelerator-utils/types/Site";
2
+
3
+ const SITE: Site = {
2
4
  owner: 'Steve Fenton',
3
5
  url: 'https://astro.stevefenton.co.uk',
4
6
  feedUrl: '/articles/feed.xml',
@@ -1,4 +1,4 @@
1
- import type { NavPage } from '@util/TempNavPage';
1
+ import type { NavPage } from 'astro-accelerator-utils/types/NavPage';
2
2
 
3
3
  export const menu: (NavPage | 'categories' | 'tags' | 'toptags')[] = [
4
4
  'categories',
@@ -1,4 +1,4 @@
1
- import type { NavPage } from '@util/TempNavPage';
1
+ import type { NavPage } from 'astro-accelerator-utils/types/NavPage';
2
2
 
3
3
  export const menu: (NavPage | 'auto')[] = [
4
4
  'auto'
@@ -2,7 +2,7 @@
2
2
  // warning: This file is overwritten by Astro Accelerator
3
3
 
4
4
  // For listing all articles in this folder
5
- import { Cache, PostFiltering, PostOrdering, PostPaging } from 'astro-accelerator-utils';
5
+ import { PostFiltering, PostOrdering, PostPaging } from 'astro-accelerator-utils';
6
6
  import { Translations, Lang } from '@util/Languages';
7
7
  import type { Page, MarkdownInstance } from 'astro';
8
8
  import { Frontmatter, SITE } from '@config';
@@ -33,35 +33,19 @@ const frontmatter: Frontmatter = {
33
33
  const _ = Lang(lang);
34
34
 
35
35
  // Logic
36
- type CacheData = {
37
- posts: MarkdownInstance<Record<string, any>>[];
38
- }
39
-
40
- export async function getCacheData() {
41
- const key = 'pages_articles_[page]';
42
-
43
- let cacheData: CacheData = await Cache.getItem(key);
44
-
45
- if (cacheData == null) {
46
- // This uses a relative glob, so we only look in the current collection
47
- const sourcePosts = await Astro.glob('./**/*.md');
48
-
49
- cacheData = { posts: []};
50
-
51
- cacheData.posts = sourcePosts
52
- .filter(PostFiltering.isListable)
53
- .sort(PostOrdering.sortByPubDateDesc);
54
-
55
- await Cache.setItem(key, cacheData);
56
- }
36
+ export async function getData() {
37
+ const sourcePosts = await Astro.glob('./**/*.md');
38
+ const posts = sourcePosts
39
+ .filter(PostFiltering.isListable)
40
+ .sort(PostOrdering.sortByPubDateDesc);
57
41
 
58
- return cacheData;
42
+ return posts;
59
43
  }
60
44
 
61
45
  export async function getStaticPaths({ paginate }: any) {
62
- let data = await getCacheData();
63
- return paginate(data.posts, {
64
- props: { pubDate: data.posts[0].frontmatter.pubDate },
46
+ let data = await getData();
47
+ return paginate(data, {
48
+ props: { pubDate: data[0].frontmatter.pubDate },
65
49
  pageSize: SITE.pageSize
66
50
  });
67
51
  }
@@ -2,11 +2,13 @@
2
2
 
3
3
  // Generates an ATOM feed of recent posts
4
4
  import { SITE } from '@config';
5
- import { Markdown, PostFiltering, Urls } from 'astro-accelerator-utils';
5
+ import { Markdown, PostFiltering, UrlFormatter } from 'astro-accelerator-utils';
6
6
 
7
7
  async function getData() {
8
8
  //@ts-ignore
9
9
  const allArticles = import.meta.glob('./**/*.md');
10
+ const urlFormatter = new UrlFormatter(SITE.url);
11
+ const markdown = new Markdown();
10
12
 
11
13
  let articles = [];
12
14
 
@@ -14,7 +16,7 @@ async function getData() {
14
16
  const article: any = await allArticles[path]();
15
17
 
16
18
  if (PostFiltering.isListable(article)) {
17
- article.frontmatter.title = await Markdown.getTextFrom(article.frontmatter.title ?? '');
19
+ article.frontmatter.title = await markdown.getTextFrom(article.frontmatter.title ?? '');
18
20
 
19
21
  articles.push({
20
22
  url: article.url,
@@ -32,7 +34,7 @@ async function getData() {
32
34
  <entry>
33
35
  <title>${a.frontmatter.title ?? ''}</title>
34
36
  <link href="${ SITE.url + a.url }" />
35
- <id>${ SITE.url + Urls.addSlashToAddress(a.url, SITE) }</id>
37
+ <id>${ SITE.url + urlFormatter.addSlashToAddress(a.url) }</id>
36
38
  <published>${ a.frontmatter.pubDate }</published>
37
39
  <updated>${ a.frontmatter.pubDate ?? a.frontmatter.pubDate }</updated>
38
40
  <summary>${ a.frontmatter.description ?? '' }</summary>
@@ -2,7 +2,7 @@
2
2
  // warning: This file is overwritten by Astro Accelerator
3
3
 
4
4
  // For listing all articles in this folder
5
- import { Cache, PostFiltering, PostOrdering, PostQueries, PostPaging } from 'astro-accelerator-utils';
5
+ import { PostFiltering, PostOrdering, PostQueries, PostPaging } from 'astro-accelerator-utils';
6
6
  import { Translations, Lang } from '@util/Languages';
7
7
  import type { Page, MarkdownInstance } from 'astro';
8
8
  import { SITE, Frontmatter } from '@config';
@@ -32,45 +32,36 @@ frontmatter.pubDate = pubDate;
32
32
  const _ = Lang(lang);
33
33
 
34
34
  // Logic
35
- type CacheData = {
35
+ type AuthorData = {
36
36
  posts: MarkdownInstance<Record<string, any>>[];
37
37
  authors: string[];
38
38
  }
39
39
 
40
- export async function getCacheData() {
41
- const key = 'pages_authors_[author]_[page]';
42
-
43
- let cacheData: CacheData = await Cache.getItem(key);
44
-
45
- if (cacheData == null) {
46
- const sourcePosts = await Astro.glob('../../**/*.md');
47
-
48
- cacheData = { posts: [], authors: []};
49
-
50
- cacheData.posts = sourcePosts
51
- .filter(PostFiltering.isListable)
52
- .sort(PostOrdering.sortByPubDateDesc);
53
-
54
- cacheData.posts.forEach(p => {
55
- const auths: string[] = p.frontmatter.authors ?? [];
56
- if (auths.length == 0) {
57
- console.log('No authors found', p.url);
40
+ export async function getData() {
41
+ const sourcePosts = await Astro.glob('../../**/*.md');
42
+ const data: AuthorData = { posts: [], authors: []};
43
+
44
+ data.posts = sourcePosts
45
+ .filter(PostFiltering.isListable)
46
+ .sort(PostOrdering.sortByPubDateDesc);
47
+
48
+ data.posts.forEach(p => {
49
+ const auths: string[] = p.frontmatter.authors ?? [];
50
+ if (auths.length == 0) {
51
+ console.log('No authors found', p.url);
52
+ }
53
+ auths.forEach(a => {
54
+ if (!data.authors.includes(a)) {
55
+ data.authors.push(a);
58
56
  }
59
- auths.forEach(a => {
60
- if (!cacheData.authors.includes(a)) {
61
- cacheData.authors.push(a);
62
- }
63
- });
64
57
  });
58
+ });
65
59
 
66
- await Cache.setItem(key, cacheData);
67
- }
68
-
69
- return cacheData;
60
+ return data;
70
61
  }
71
62
 
72
63
  export async function getStaticPaths({ paginate }: any) {
73
- let data = await getCacheData();
64
+ let data = await getData();
74
65
 
75
66
  return data.authors.map(a => {
76
67
  const filtered = data.posts.filter(p => {
@@ -2,7 +2,7 @@
2
2
  // warning: This file is overwritten by Astro Accelerator
3
3
 
4
4
  // For listing by frontmatter.categories
5
- import { Cache, PostFiltering, PostOrdering, PostPaging } from 'astro-accelerator-utils';
5
+ import { PostFiltering, PostOrdering, PostPaging } from 'astro-accelerator-utils';
6
6
  import { Translations, Lang } from '@util/Languages';
7
7
  import type { Page, MarkdownInstance } from 'astro';
8
8
  import { SITE, Frontmatter } from '@config';
@@ -36,46 +36,38 @@ const frontmatter: Frontmatter = {
36
36
  const _ = Lang(lang);
37
37
 
38
38
  // Logic
39
- type CacheData = {
39
+ type CategoryData = {
40
40
  posts: MarkdownInstance<Record<string, any>>[];
41
41
  categories: string[];
42
42
  }
43
43
 
44
- export async function getCacheData() {
45
- const key = 'pages_articles_[category]_[page]';
44
+ export async function getData() {
45
+ // TODO: Replace with call to Posts.all()
46
+ const sourcePosts = await Astro.glob('../../**/*.md');
47
+
48
+ const data: CategoryData = { posts: [], categories: []};
46
49
 
47
- let cacheData: CacheData = await Cache.getItem(key);
50
+ data.posts = sourcePosts
51
+ .filter(PostFiltering.isListable)
52
+ .sort(PostOrdering.sortByPubDateDesc);
48
53
 
49
- if (cacheData == null) {
50
- // This uses a relative glob, so we only look in the current collection
51
- const sourcePosts = await Astro.glob('../../**/*.md');
52
-
53
- cacheData = { posts: [], categories: []};
54
-
55
- cacheData.posts = sourcePosts
56
- .filter(PostFiltering.isListable)
57
- .sort(PostOrdering.sortByPubDateDesc);
58
-
59
- cacheData.posts.forEach(p => {
60
- const auths: string[] = p.frontmatter.categories ?? [];
61
- if (auths.length == 0) {
62
- console.log('No categories found', p.url);
54
+ data.posts.forEach(p => {
55
+ const auths: string[] = p.frontmatter.categories ?? [];
56
+ if (auths.length == 0) {
57
+ console.log('No categories found', p.url);
58
+ }
59
+ auths.forEach(a => {
60
+ if (!data.categories.includes(a)) {
61
+ data.categories.push(a);
63
62
  }
64
- auths.forEach(a => {
65
- if (!cacheData.categories.includes(a)) {
66
- cacheData.categories.push(a);
67
- }
68
- });
69
63
  });
70
-
71
- await Cache.setItem(key, cacheData);
72
- }
64
+ });
73
65
 
74
- return cacheData;
66
+ return data;
75
67
  }
76
68
 
77
69
  export async function getStaticPaths({ paginate }: any) {
78
- let data = await getCacheData();
70
+ let data = await getData();
79
71
 
80
72
  return data.categories.map(c => {
81
73
  const filtered = data.posts.filter(p => {
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  // warning: This file is overwritten by Astro Accelerator
3
3
 
4
- import { getCacheData } from './[page].astro';
4
+ import { getData } from './[page].astro';
5
5
  import Redirect from 'src/layouts/Redirect.astro'
6
6
 
7
7
  export async function getStaticPaths() {
8
- let data = await getCacheData();
8
+ let data = await getData();
9
9
 
10
10
  return data.categories.map(item => {
11
11
  return { params: { category: item.toLowerCase().replace(' ', '-') }}
@@ -1,7 +1,9 @@
1
1
  ---
2
- import { PostQueries, PostOrdering } from 'astro-accelerator-utils';
2
+ import { PostQueries, PostOrdering, UrlFormatter } from 'astro-accelerator-utils';
3
+ import { SITE } from '@config';
3
4
 
4
5
  // Logic
6
+ const urlFormatter = new UrlFormatter(SITE.url);
5
7
  const allPages = await PostQueries.getPages();
6
8
  const missingBanner = allPages.filter(p => p.frontmatter.bannerImage == null && p.frontmatter.layout != 'src/layouts/Redirect.astro');
7
9
  const pageCount = missingBanner.length;
@@ -25,7 +27,7 @@ const pages = missingBanner.sort(PostOrdering.sortByPubDateDesc).slice(0, Math.m
25
27
  </thead>
26
28
  {pages.map(p =>
27
29
  <tr>
28
- <td><a href={ p.url }>{ p.frontmatter.title }</a></td>
30
+ <td><a href={ urlFormatter.addSlashToAddress(p.url) }>{ p.frontmatter.title }</a></td>
29
31
  <td>{ p.frontmatter.pubDate }</td>
30
32
  <td>{ p.frontmatter.modDate }</td>
31
33
  </tr>
@@ -1,7 +1,9 @@
1
1
  ---
2
- import { PostQueries, PostOrdering } from 'astro-accelerator-utils';
2
+ import { PostQueries, PostOrdering, UrlFormatter } from 'astro-accelerator-utils';
3
+ import { SITE } from '@config';
3
4
 
4
5
  // Logic
6
+ const urlFormatter = new UrlFormatter(SITE.url);
5
7
  const allPages = await PostQueries.getPages();
6
8
  const missingMeta = allPages.filter(p => (p.frontmatter.keywords == null || p.frontmatter.description == null) && p.frontmatter.layout != 'src/layouts/Redirect.astro');
7
9
  const pageCount = missingMeta.length;
@@ -25,7 +27,7 @@ const pages = missingMeta.sort(PostOrdering.sortByPubDateDesc).slice(0, Math.min
25
27
  </thead>
26
28
  {pages.map(p =>
27
29
  <tr>
28
- <td><a href={ p.url }>{ p.frontmatter.title }</a></td>
30
+ <td><a href={ urlFormatter.addSlashToAddress(p.url) }>{ p.frontmatter.title }</a></td>
29
31
  <td>{ p.frontmatter.pubDate }</td>
30
32
  <td>{ p.frontmatter.modDate }</td>
31
33
  </tr>
@@ -1,7 +1,9 @@
1
1
  ---
2
- import { PostQueries } from 'astro-accelerator-utils';
2
+ import { PostQueries, UrlFormatter } from 'astro-accelerator-utils';
3
+ import { SITE } from '@config';
3
4
 
4
5
  // Logic
6
+ const urlFormatter = new UrlFormatter(SITE.url);
5
7
  const allPages = await PostQueries.getPages();
6
8
  const missingMeta = allPages.filter(p => (p.frontmatter.pubDate == null && p.frontmatter.layout != 'src/layouts/Redirect.astro'));
7
9
  const pageCount = missingMeta.length;
@@ -25,7 +27,7 @@ const pages = missingMeta.slice(0, Math.min(50, pageCount));
25
27
  </thead>
26
28
  {pages.map(p =>
27
29
  <tr>
28
- <td><a href={ p.url }>{ p.frontmatter.title }</a></td>
30
+ <td><a href={ urlFormatter.addSlashToAddress(p.url) }>{ p.frontmatter.title }</a></td>
29
31
  <td>{ p.frontmatter.pubDate }</td>
30
32
  <td>{ p.frontmatter.modDate }</td>
31
33
  </tr>
@@ -1,7 +1,9 @@
1
1
  ---
2
- import { PostQueries, PostOrdering } from 'astro-accelerator-utils';
2
+ import { PostQueries, PostOrdering, PostFiltering, UrlFormatter } from 'astro-accelerator-utils';
3
+ import { SITE } from '@config';
3
4
 
4
5
  // Logic
6
+ const urlFormatter = new UrlFormatter(SITE.url);
5
7
  const allPages = await PostQueries.getPages();
6
8
  const pageCount = allPages.length;
7
9
  const pages = allPages.sort(PostOrdering.sortByModDate).slice(0, Math.min(50, pageCount));
@@ -24,7 +26,14 @@ const pages = allPages.sort(PostOrdering.sortByModDate).slice(0, Math.min(50, pa
24
26
  </thead>
25
27
  {pages.map(p =>
26
28
  <tr>
27
- <td><a href={ p.url }>{ p.frontmatter.title }</a></td>
29
+ <td>
30
+ {PostFiltering.isListable(p) && (
31
+ <a href={ urlFormatter.addSlashToAddress(p.url) }>{ p.frontmatter.title }</a>
32
+ )}
33
+ {PostFiltering.isListable(p) == false && (
34
+ <span>{ p.frontmatter.title }</span>
35
+ )}
36
+ </td>
28
37
  <td>{ p.frontmatter.pubDate }</td>
29
38
  <td>{ p.frontmatter.modDate }</td>
30
39
  </tr>
@@ -1,14 +1,17 @@
1
1
  // warning: This file is overwritten by Astro Accelerator
2
2
 
3
+ import { Markdown, PostFiltering, UrlFormatter } from 'astro-accelerator-utils';
3
4
  import type { MarkdownInstance } from 'astro';
4
5
  import { SITE } from '@config';
5
- import { Markdown, PostFiltering, Urls } from 'astro-accelerator-utils';
6
6
 
7
7
  const getData = async () => {
8
8
  //@ts-ignore
9
9
  const allPages = import.meta.glob('./**/*.md');
10
10
  const items = [];
11
11
 
12
+ const urlFormatter = new UrlFormatter(SITE.url);
13
+ const markdown = new Markdown();
14
+
12
15
  for (const path in allPages) {
13
16
  const page = await allPages[path]() as MarkdownInstance<Record<string, any>>;
14
17
 
@@ -23,7 +26,7 @@ const getData = async () => {
23
26
  }
24
27
 
25
28
  const headings = await page.getHeadings();
26
- const title = await Markdown.getTextFrom(page.frontmatter.title ?? '');
29
+ const title = await markdown.getTextFrom(page.frontmatter.title ?? '');
27
30
 
28
31
  items.push({
29
32
  title: title,
@@ -32,7 +35,7 @@ const getData = async () => {
32
35
  }),
33
36
  description: page.frontmatter.description ?? '',
34
37
  tags: page.frontmatter.tags ?? [],
35
- url: SITE.url + Urls.addSlashToAddress(url, SITE),
38
+ url: SITE.url + urlFormatter.addSlashToAddress(url),
36
39
  date: page.frontmatter.pubDate ?? ''
37
40
  });
38
41
  }
@@ -2,13 +2,14 @@
2
2
 
3
3
  // Generates an ATOM feed of recent posts
4
4
  import { SITE } from '@config';
5
- import { PostFiltering, Urls } from 'astro-accelerator-utils';
5
+ import { PostFiltering, UrlFormatter } from 'astro-accelerator-utils';
6
6
 
7
7
  async function getData() {
8
8
  //@ts-ignore
9
9
  const allPages = import.meta.glob('./**/*.md');
10
10
 
11
11
  let pages = [];
12
+ const urlFormatter = new UrlFormatter(SITE.url);
12
13
 
13
14
  for (const path in allPages) {
14
15
  const article: any = await allPages[path]();
@@ -17,7 +18,7 @@ async function getData() {
17
18
  if (addToSitemap) {
18
19
  pages.push(`
19
20
  <url>
20
- <loc>${ SITE.url + Urls.addSlashToAddress(article.url, SITE) }</loc>
21
+ <loc>${ SITE.url + urlFormatter.addSlashToAddress(article.url) }</loc>
21
22
  <lastmod>${ article.frontmatter.pubDate }</lastmod>
22
23
  </url>`);
23
24
  }
@@ -2,7 +2,7 @@
2
2
  // warning: This file is overwritten by Astro Accelerator
3
3
 
4
4
  // For listing by frontmatter.tags
5
- import {Cache, PostFiltering, PostOrdering, PostPaging } from 'astro-accelerator-utils';
5
+ import { PostFiltering, PostOrdering, PostPaging } from 'astro-accelerator-utils';
6
6
  import { Translations, Lang } from '@util/Languages';
7
7
  import type { Page, MarkdownInstance } from 'astro';
8
8
  import { SITE, Frontmatter } from '@config';
@@ -41,41 +41,32 @@ type CacheData = {
41
41
  tags: string[];
42
42
  }
43
43
 
44
- export async function getCacheData() {
45
- const key = 'pages_articles_[tag]_[page]';
46
-
47
- let cacheData: CacheData = await Cache.getItem(key);
48
-
49
- if (cacheData == null) {
50
- // This uses a relative glob, so we only look in the current collection
51
- const sourcePosts = await Astro.glob('../../**/*.md');
44
+ export async function getData() {
45
+ const sourcePosts = await Astro.glob('../../**/*.md');
52
46
 
53
- cacheData = { posts: [], tags: []};
54
-
55
- cacheData.posts = sourcePosts
56
- .filter(PostFiltering.isListable)
57
- .sort(PostOrdering.sortByPubDateDesc);
58
-
59
- cacheData.posts.forEach(p => {
60
- const auths: string[] = p.frontmatter.tags ?? [];
61
- if (auths.length == 0) {
62
- console.log('No categories found', p.url);
47
+ const data: CacheData = { posts: [], tags: []};
48
+
49
+ data.posts = sourcePosts
50
+ .filter(PostFiltering.isListable)
51
+ .sort(PostOrdering.sortByPubDateDesc);
52
+
53
+ data.posts.forEach(p => {
54
+ const auths: string[] = p.frontmatter.tags ?? [];
55
+ if (auths.length == 0) {
56
+ console.log('No categories found', p.url);
57
+ }
58
+ auths.forEach(a => {
59
+ if (!data.tags.includes(a)) {
60
+ data.tags.push(a);
63
61
  }
64
- auths.forEach(a => {
65
- if (!cacheData.tags.includes(a)) {
66
- cacheData.tags.push(a);
67
- }
68
- });
69
62
  });
63
+ });
70
64
 
71
- await Cache.setItem(key, cacheData);
72
- }
73
-
74
- return cacheData;
65
+ return data;
75
66
  }
76
67
 
77
68
  export async function getStaticPaths({ paginate }: any) {
78
- let data = await getCacheData();
69
+ let data = await getData();
79
70
 
80
71
  return data.tags.map(t => {
81
72
  const filtered = data.posts.filter(p => {
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  // warning: This file is overwritten by Astro Accelerator
3
3
 
4
- import { getCacheData } from './[page].astro';
4
+ import { getData } from './[page].astro';
5
5
  import Redirect from 'src/layouts/Redirect.astro'
6
6
 
7
7
  export async function getStaticPaths() {
8
- let data = await getCacheData();
8
+ let data = await getData();
9
9
 
10
10
  return data.tags.map(item => {
11
11
  return { params: { tag: item.toLowerCase().replace(' ', '-') }}
@@ -1,11 +1,10 @@
1
1
  ---
2
- import { Markdown, Urls } from 'astro-accelerator-utils';
2
+ import { Markdown, UrlFormatter } from 'astro-accelerator-utils';
3
3
  import type { MarkdownInstance } from 'astro';
4
4
  import { SITE, Frontmatter } from '@config';
5
5
  import { getImageInfo } from '@util/custom-markdown.mjs';
6
6
  import AuthorsMini from '@components/AuthorsMini.astro';
7
7
 
8
-
9
8
  // Properties
10
9
  type Props = {
11
10
  lang: string;
@@ -14,11 +13,18 @@ type Props = {
14
13
  const { lang, posts } = Astro.props as Props;
15
14
 
16
15
  // Logic
16
+ const urlFormatter = new UrlFormatter(SITE.url);
17
+ const markdown = new Markdown();
18
+
17
19
  type ImageInfo = {
18
20
  src: string;
19
21
  srcset: string;
20
22
  sizes: string;
21
23
  class: string;
24
+ metadata: {
25
+ width: number;
26
+ height: number;
27
+ }
22
28
  };
23
29
 
24
30
  type Article = {
@@ -35,11 +41,11 @@ for (let p of posts) {
35
41
  url: p.url ?? '',
36
42
  frontmatter: p.frontmatter,
37
43
  img: p.frontmatter.bannerImage
38
- ? getImageInfo(p.frontmatter.bannerImage.src, '', SITE.images.listerSize)
39
- : null
44
+ ? getImageInfo(p.frontmatter.bannerImage.src, '', SITE.images.listerSize)
45
+ : null
40
46
  };
41
47
 
42
- item.frontmatter.title = await Markdown.getTextFrom(p.frontmatter.title);
48
+ item.frontmatter.title = await markdown.getTextFrom(p.frontmatter.title);
43
49
 
44
50
  articles.push(item)
45
51
  }
@@ -54,7 +60,7 @@ function getLoadingAttribute() {
54
60
  ---
55
61
  <ul class="post-list anim-show-parent">
56
62
  {articles.map((post) => (
57
- <li class="list-item" data-destination={ Urls.addSlashToAddress(post.url, SITE) } data-image={ (post.frontmatter.bannerImage?.src.length > 0).toString() }>
63
+ <li class="list-item" data-destination={ urlFormatter.addSlashToAddress(post.url) } data-image={ (post.frontmatter.bannerImage?.src.length > 0).toString() }>
58
64
  <article>
59
65
  <div class="list-item-image">
60
66
  {post.img && (
@@ -64,12 +70,14 @@ function getLoadingAttribute() {
64
70
  src={ post.img.src }
65
71
  alt={ post.frontmatter.bannerImage.alt }
66
72
  class={ post.img.class }
73
+ width={ post.img.metadata?.width }
74
+ height={ post.img.metadata?.height }
67
75
  loading={ getLoadingAttribute() } />
68
76
  )}
69
77
  </div>
70
78
  <div class="list-item-content">
71
79
  <h3>
72
- <a href={ Urls.addSlashToAddress(post.url, SITE) }>{ post.frontmatter.title }</a>
80
+ <a href={ urlFormatter.addSlashToAddress(post.url) }>{ post.frontmatter.title }</a>
73
81
  </h3>
74
82
  <AuthorsMini lang={ lang } frontmatter={ post.frontmatter as Frontmatter } />
75
83
  </div>
@@ -1,5 +1,5 @@
1
1
  ---
2
- import { Dates, Urls, PostQueries } from 'astro-accelerator-utils';
2
+ import { PostQueries, DateFormatter, UrlFormatter } from 'astro-accelerator-utils';
3
3
  import { SITE, Frontmatter } from '@config';
4
4
  import { Translations, Lang } from '@util/Languages';
5
5
  import { getImageInfo } from '@util/custom-markdown.mjs';
@@ -15,6 +15,8 @@ const { lang, frontmatter } = Astro.props as Props;
15
15
  const _ = Lang(lang);
16
16
 
17
17
  // Logic
18
+ const dateFormatter = new DateFormatter(SITE.dateOptions);
19
+ const urlFormatter = new UrlFormatter(SITE.url);
18
20
  const authorList = await PostQueries.getAuthors(frontmatter);
19
21
 
20
22
  // Get image info
@@ -35,16 +37,16 @@ const authorImage = authorList?.image?.src
35
37
  <div class="author-info">
36
38
  <span>{ _(Translations.post.written_by) }
37
39
  {authorList.mainAuthor &&
38
- <a href={ Urls.addSlashToAddress(authorList.mainAuthor.url, SITE) + '1/' } itemprop="author">{ authorList.mainAuthor.frontmatter.title }</a>
40
+ <a href={ urlFormatter.addSlashToAddress(authorList.mainAuthor.url) + '1/' } itemprop="author">{ authorList.mainAuthor.frontmatter.title }</a>
39
41
  }{authorList.contributors.map((writer) => (
40
- <a href={ Urls.addSlashToAddress(writer.url, SITE) + '1/' } itemprop="contributor">{ writer.frontmatter.title }</a>
42
+ <a href={ urlFormatter.addSlashToAddress(writer.url) + '1/' } itemprop="contributor">{ writer.frontmatter.title }</a>
41
43
  ))}.
42
44
  <br /><time datetime={ frontmatter.pubDate.toString() } itemprop="datePublished">
43
- { Dates.formatDate(frontmatter, lang, SITE) }
45
+ { dateFormatter.formatDate(frontmatter.pubDate, lang) }
44
46
  </time>
45
47
  {frontmatter.modDate &&
46
48
  <br /><time datetime={ frontmatter.modDate.toString() } itemprop="dateModified">
47
- { _(Translations.post.last_modified) } { Dates.formatModifiedDate(frontmatter, lang, SITE) }
49
+ { _(Translations.post.last_modified) } { dateFormatter.formatDate(frontmatter.modDate, lang) }
48
50
  </time>
49
51
  }
50
52
  </span>
@@ -1,5 +1,5 @@
1
1
  ---
2
- import { Dates, PostQueries } from 'astro-accelerator-utils';
2
+ import { PostQueries, DateFormatter } from 'astro-accelerator-utils';
3
3
  import { SITE, Frontmatter } from '@config';
4
4
  import { Translations, Lang } from '@util/Languages';;
5
5
 
@@ -14,6 +14,7 @@ const { lang, frontmatter } = Astro.props as Props;
14
14
  const _ = Lang(lang);
15
15
 
16
16
  // Logic
17
+ const dateFormatter = new DateFormatter(SITE.dateOptions);
17
18
  const authorList = await PostQueries.getAuthors(frontmatter);
18
19
  ---
19
20
  {authorList.writers.length > 0 &&
@@ -24,7 +25,7 @@ const authorList = await PostQueries.getAuthors(frontmatter);
24
25
  <span>{ writer.frontmatter.title }</span>
25
26
  ))}.<br />
26
27
  <time datetime={ frontmatter.pubDate.toString() }>
27
- { Dates.formatDate(frontmatter, lang, SITE) }
28
+ { dateFormatter.formatDate(frontmatter, lang) }
28
29
  </time>
29
30
  </span>
30
31
  </div>
@@ -1,5 +1,5 @@
1
1
  ---
2
- import { Urls, PostQueries } from 'astro-accelerator-utils';
2
+ import { PostQueries, UrlFormatter } from 'astro-accelerator-utils';
3
3
  import { SITE, Frontmatter } from '@config';
4
4
  import { Translations, Lang } from '@util/Languages';
5
5
 
@@ -15,6 +15,7 @@ const { lang } = Astro.props as Props;
15
15
  const _ = Lang(lang);
16
16
 
17
17
  // Logic
18
+ const urlFormatter = new UrlFormatter(SITE.url);
18
19
  const currentUrl = new URL(Astro.request.url);
19
20
  const navPages = await PostQueries.getBreadcrumbs(currentUrl, SITE);
20
21
  ---
@@ -23,7 +24,7 @@ const navPages = await PostQueries.getBreadcrumbs(currentUrl, SITE);
23
24
  {navPages.map((page, index) => (
24
25
  <li property="itemListElement" typeof="ListItem">
25
26
  <meta property="position" content={ index.toString() } />
26
- <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>
27
+ <a property="item" typeof="WebPage" href={ urlFormatter.addSlashToAddress(page.url) } aria-current={ page.ariaCurrent } rel={ page.rel }><span property="name">{ page.title }</span></a>
27
28
  </li>
28
29
  ))}
29
30
  </ol>
@@ -1,5 +1,5 @@
1
1
  ---
2
- import type { NavPage } from '@util/TempNavPage';
2
+ import type { NavPage } from 'astro-accelerator-utils/types/NavPage';
3
3
 
4
4
  // Properties
5
5
  type Props = {
@@ -9,7 +9,7 @@ type Props = {
9
9
  const { lang, page } = Astro.props as Props;
10
10
  ---
11
11
  <div class="footer-column">
12
- <h2>{ page.title }</h2>
12
+ <h2><Fragment set:html={page.title} /></h2>
13
13
  <ul>
14
14
  { page.children.sort((a, b) => a.order - b.order).map((child) => (
15
15
  <li>
@@ -1,5 +1,5 @@
1
1
  ---
2
- import { Urls, PostQueries, PostFiltering } from 'astro-accelerator-utils';
2
+ import { PostQueries, PostFiltering, UrlFormatter } from 'astro-accelerator-utils';
3
3
  import { SITE, Frontmatter } from '@config';
4
4
  import { Translations, Lang } from '@util/Languages';
5
5
 
@@ -15,6 +15,7 @@ const { lang } = Astro.props as Props;
15
15
  const _ = Lang(lang);
16
16
 
17
17
  // Logic
18
+ const urlFormatter = new UrlFormatter(SITE.url);
18
19
  const search = (await PostQueries.getPages(PostFiltering.isSearch))[0] ?? null;
19
20
 
20
21
  ---
@@ -29,7 +30,7 @@ const search = (await PostQueries.getPages(PostFiltering.isSearch))[0] ?? null;
29
30
  </svg></a>
30
31
  <a href={ (SITE.subfolder ?? '') + '/' } class="site-title" translate="no">{ SITE.title }</a>
31
32
  {search != null &&
32
- <a href={ Urls.addSlashToAddress(search.url, SITE) } class="search-icon" title={ _(Translations.header.open_search) }><svg xmlns="http://www.w3.org/2000/svg"
33
+ <a href={ urlFormatter.addSlashToAddress(search.url) } class="search-icon" title={ _(Translations.header.open_search) }><svg xmlns="http://www.w3.org/2000/svg"
33
34
  width="40" height="40" viewBox="0 0 24 24" stroke-width="1"
34
35
  fill="none" stroke-linecap="round" stroke-linejoin="round">
35
36
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
@@ -1,5 +1,5 @@
1
1
  ---
2
- import { Markdown, Urls } from 'astro-accelerator-utils';
2
+ import { Markdown, UrlFormatter } from 'astro-accelerator-utils';
3
3
  import { SITE, OPEN_GRAPH, HEADER_SCRIPTS, Frontmatter } from '@config';
4
4
 
5
5
  // Properties
@@ -11,12 +11,15 @@ type Props = {
11
11
  const { frontmatter } = Astro.props;
12
12
 
13
13
  // Logic
14
+ const urlFormatter = new UrlFormatter(SITE.url);
15
+ const markdown = new Markdown();
16
+
14
17
  const imageSrc = frontmatter.bannerImage?.src ?? OPEN_GRAPH.image.src;
15
18
  const imageAlt = frontmatter.bannerImage?.alt ?? OPEN_GRAPH.image.alt;
16
19
  const robots = frontmatter.robots ?? 'index, follow';
17
20
  const canonicalImageSrc = new URL(imageSrc, Astro.site);
18
- const canonicalURL = Urls.addSlashToUrl(new URL(Astro.url.pathname, Astro.site + SITE.subfolder));
19
- const socialTitle = await Markdown.getTextFrom(frontmatter.title);
21
+ const canonicalURL = urlFormatter.addSlashToUrl(new URL(Astro.url.pathname, Astro.site + SITE.subfolder));
22
+ const socialTitle = await markdown.getTextFrom(frontmatter.title);
20
23
  const title = `${ socialTitle } | ${ SITE.title }`;
21
24
  ---
22
25
  <head>
@@ -1,7 +1,7 @@
1
1
  ---
2
+ import { UrlFormatter } from 'astro-accelerator-utils';
3
+ import type { NavPage } from 'astro-accelerator-utils/types/NavPage';
2
4
  import { SITE } from '@config';
3
- import type { NavPage } from '@util/TempNavPage';
4
- import { Urls } from 'astro-accelerator-utils';
5
5
 
6
6
  // Properties
7
7
  type Props = {
@@ -9,10 +9,13 @@ type Props = {
9
9
  page: NavPage
10
10
  };
11
11
  const { lang, page } = Astro.props as Props;
12
+
13
+ // Logic
14
+ const urlFormatter = new UrlFormatter(SITE.url);
12
15
  ---
13
16
  {(page.children.length == 0) && (
14
17
  <li>
15
- <a href={ Urls.addSlashToAddress(page.url, SITE) } aria-current={ page.ariaCurrent } rel={ page.rel }>{ page.title }</a>
18
+ <a href={ urlFormatter.addSlashToAddress(page.url) } aria-current={ page.ariaCurrent } rel={ page.rel }>{ page.title }</a>
16
19
  </li>
17
20
  )}
18
21
  {(page.children.length > 0) && (
@@ -1,7 +1,7 @@
1
1
  ---
2
- import { Urls } from 'astro-accelerator-utils';
2
+ import { UrlFormatter } from 'astro-accelerator-utils';
3
+ import type { Link } from 'astro-accelerator-utils/types/Link';
3
4
  import { SITE } from '@config';
4
- import type { Link } from '@util/PageLinks';
5
5
  import type { MarkdownInstance, Page } from 'astro';
6
6
  import { Translations, Lang } from '@util/Languages';
7
7
 
@@ -17,16 +17,16 @@ const { lang, page, pageLinks } = Astro.props as Props;
17
17
  const _ = Lang(lang);
18
18
 
19
19
  // Logic
20
- // -
20
+ const urlFormatter = new UrlFormatter(SITE.url);
21
21
  ---
22
22
  <nav class="post-paging" aria-label={ _(Translations.aria.paging) }>
23
23
  {page.url.prev
24
- ? <a href={ Urls.addSlashToAddress(page.url.prev, SITE) }>{ _(Translations.articles.previous) }</a>
24
+ ? <a href={ urlFormatter.addSlashToAddress(page.url.prev) }>{ _(Translations.articles.previous) }</a>
25
25
  : <span>{ _(Translations.articles.previous) }</span>}
26
26
  {pageLinks.map((link) => (
27
- <a href={ Urls.addSlashToAddress(link.url, SITE) } aria-current={ link.ariaCurrent } class={ link.class }>{ link.title }</a>
27
+ <a href={ urlFormatter.addSlashToAddress(link.url) } aria-current={ link.ariaCurrent } class={ link.class }>{ link.title }</a>
28
28
  ))}
29
29
  {page.url.next
30
- ? <a href={ Urls.addSlashToAddress(page.url.next, SITE) }>{ _(Translations.articles.next) }</a>
30
+ ? <a href={ urlFormatter.addSlashToAddress(page.url.next) }>{ _(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 { Urls, PostQueries, PostFiltering, PostOrdering } from 'astro-accelerator-utils';
4
+ import { PostQueries, PostFiltering, PostOrdering, UrlFormatter } from 'astro-accelerator-utils';
5
5
  import { getImageInfo } from '@util/custom-markdown.mjs'
6
6
 
7
7
  import AuthorsMini from '@components/AuthorsMini.astro';
@@ -15,6 +15,7 @@ type Props = {
15
15
  const { lang, frontmatter, headings } = Astro.props as Props;
16
16
 
17
17
  // Logic
18
+ const urlFormatter = new UrlFormatter(SITE.url);
18
19
  let posts: MarkdownInstance<Record<string, any>>[] = [];
19
20
  const parentCagory = (frontmatter.categories ?? [null])[0];
20
21
 
@@ -52,7 +53,7 @@ const articles = posts.map(p => {
52
53
  {articles.length > 0 &&
53
54
  <ul class="post-list anim-show-parent">
54
55
  {articles.map((post) => (
55
- <li class="list-item" data-destination={ Urls.addSlashToAddress(post.url, SITE) } data-image={ (post.frontmatter.bannerImage?.src.length > 0).toString() }>
56
+ <li class="list-item" data-destination={ urlFormatter.addSlashToAddress(post.url) } data-image={ (post.frontmatter.bannerImage?.src.length > 0).toString() }>
56
57
  <article>
57
58
  <div class="list-item-image">
58
59
  {post.img && (
@@ -67,7 +68,7 @@ const articles = posts.map(p => {
67
68
  </div>
68
69
  <div class="list-item-content">
69
70
  <h3>
70
- <a href={ Urls.addSlashToAddress(post.url, SITE) }>{ post.frontmatter.title }</a>
71
+ <a href={ urlFormatter.addSlashToAddress(post.url) }>{ post.frontmatter.title }</a>
71
72
  </h3>
72
73
  <AuthorsMini lang={ lang } frontmatter={ post.frontmatter as Frontmatter } />
73
74
  </div>
@@ -22,9 +22,12 @@ const { frontmatter, headings } = Astro.props as Props;
22
22
  const lang = frontmatter.lang ?? SITE.default.lang;
23
23
  const textDirection = frontmatter.dir ?? SITE.default.dir;
24
24
 
25
- const title = await Markdown.getInlineHtmlFrom(frontmatter.title ?? SITE.title);
25
+ // Logic
26
+ const markdown = new Markdown();
27
+
28
+ const title = await markdown.getInlineHtmlFrom(frontmatter.title ?? SITE.title);
26
29
  const subtitle = frontmatter.subtitle
27
- ? await Markdown.getInlineHtmlFrom(frontmatter.subtitle)
30
+ ? await markdown.getInlineHtmlFrom(frontmatter.subtitle)
28
31
  : null;
29
32
 
30
33
  const site_url = SITE.url;
@@ -55,6 +55,17 @@ export function getImageInfo(src, className, sizes) {
55
55
  info.srcset = `${imgSmall} ${size.small}w, ${imgMedium} ${size.medium}w, ${imgLarge}`;
56
56
  info.sizes = sizes;
57
57
  info.class = (className ?? '' + ' resp-img').trim();
58
+ info.metadata = null;
59
+
60
+ try {
61
+ let metaAddress = path.join(workingDirectory, 'public', src + '.json');
62
+
63
+ if (fs.existsSync(metaAddress)) {
64
+ info.metadata = JSON.parse(fs.readFileSync(metaAddress));
65
+ }
66
+ } catch (e) {
67
+ console.warn(e);
68
+ }
58
69
 
59
70
  return info;
60
71
  }
@@ -69,13 +80,6 @@ export function attributeMarkdown() {
69
80
  const hast = h(node.name, node.attributes);
70
81
 
71
82
  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
-
79
83
  // Process the image
80
84
  const info = getImageInfo(hast.properties.src, hast.properties.class, SITE.images.contentSize);
81
85
 
@@ -84,9 +88,9 @@ export function attributeMarkdown() {
84
88
  hast.properties.sizes = info.sizes;
85
89
  hast.properties.class = info.class;
86
90
 
87
- if (metadata) {
88
- hast.properties.width = metadata.width;
89
- hast.properties.height = metadata.height;
91
+ if (info.metadata) {
92
+ hast.properties.width = info.metadata.width;
93
+ hast.properties.height = info.metadata.height;
90
94
  }
91
95
  }
92
96
 
@@ -1,10 +0,0 @@
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
- }