astro-accelerator 0.0.27 → 0.0.28

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.27",
2
+ "version": "0.0.28",
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.24",
29
+ "astro-accelerator-utils": "^0.0.26",
30
30
  "hast-util-from-selector": "^2.0.0",
31
31
  "remark-directive": "^2.0.1"
32
32
  },
@@ -1,9 +1,9 @@
1
1
  ---
2
- import { Dates, Urls } from 'astro-accelerator-utils';
2
+ import { Dates, Urls, PostQueries } from 'astro-accelerator-utils';
3
3
  import { SITE, Frontmatter } from '@config';
4
4
  import { Translations, Lang } from '@util/Languages';
5
- import { getAuthorList } from '@util/Authors';
6
5
  import { getImageInfo } from '@util/custom-markdown.mjs';
6
+ import { fetchPages } from '@util/PageQueries';
7
7
 
8
8
  // Properties
9
9
  type Props = {
@@ -16,11 +16,12 @@ const { lang, frontmatter } = Astro.props as Props;
16
16
  const _ = Lang(lang);
17
17
 
18
18
  // Logic
19
- const authorList = await getAuthorList(frontmatter);
19
+ const authorList = await PostQueries.getAuthors(fetchPages, frontmatter);
20
20
 
21
- const author = authorList.writers.slice(0, 1)[0];
22
- const authorImage = authorList?.image?.src ? getImageInfo(authorList.image.src, 'author-image', SITE.images.authorSize) : null;
23
- const contributors = authorList.writers.slice(1);
21
+ // Get image info
22
+ const authorImage = authorList?.image?.src
23
+ ? getImageInfo(authorList.image.src, 'author-image', SITE.images.authorSize)
24
+ : null;
24
25
  ---
25
26
  {authorList.writers.length > 0 &&
26
27
  <div class="post-meta">
@@ -34,9 +35,9 @@ const contributors = authorList.writers.slice(1);
34
35
  }
35
36
  <div class="author-info">
36
37
  <span>{ _(Translations.post.written_by) }
37
- {author &&
38
- <a href={ Urls.addSlashToAddress(author.url, SITE) + '1/' } itemprop="author">{ author.frontmatter.title }</a>
39
- }{contributors.map((writer) => (
38
+ {authorList.mainAuthor &&
39
+ <a href={ Urls.addSlashToAddress(authorList.mainAuthor.url, SITE) + '1/' } itemprop="author">{ authorList.mainAuthor.frontmatter.title }</a>
40
+ }{authorList.contributors.map((writer) => (
40
41
  <a href={ Urls.addSlashToAddress(writer.url, SITE) + '1/' } itemprop="contributor">{ writer.frontmatter.title }</a>
41
42
  ))}.
42
43
  <br /><time datetime={ frontmatter.pubDate.toString() } itemprop="datePublished">
@@ -1,8 +1,8 @@
1
1
  ---
2
+ import { Dates, PostQueries } from 'astro-accelerator-utils';
2
3
  import { SITE, Frontmatter } from '@config';
3
4
  import { Translations, Lang } from '@util/Languages';;
4
- import { Dates } from 'astro-accelerator-utils';
5
- import { getAuthorList } from '@util/Authors';
5
+ import { fetchPages } from '@util/PageQueries';
6
6
 
7
7
  // Properties
8
8
  type Props = {
@@ -15,7 +15,7 @@ const { lang, frontmatter } = Astro.props as Props;
15
15
  const _ = Lang(lang);
16
16
 
17
17
  // Logic
18
- const authorList = await getAuthorList(frontmatter);
18
+ const authorList = await PostQueries.getAuthors(fetchPages, frontmatter);
19
19
  ---
20
20
  {authorList.writers.length > 0 &&
21
21
  <div class="post-meta">
@@ -2,8 +2,8 @@ import type { MarkdownInstance } from "astro";
2
2
  import { SITE } from '@config';
3
3
  import { Cache, PostQueries, PostFiltering } from 'astro-accelerator-utils';
4
4
 
5
- export function fetchPages(): Record<string, any> {
6
- return import.meta.glob("../../../pages/**/*.md", { eager: true });
5
+ export function fetchPages(): MarkdownInstance<Record<string, any>>[] {
6
+ return import.meta.glob<any>("../../../pages/**/*.md", { eager: true }) as MarkdownInstance<Record<string, any>>[];
7
7
  }
8
8
 
9
9
  export type PagePredicate = (value: MarkdownInstance<Record<string, any>>, index: number, array: MarkdownInstance<Record<string, any>>[]) => boolean;
@@ -1,45 +0,0 @@
1
- import type { MarkdownInstance } from 'astro';
2
- import { PostQueries, PostFiltering } from "astro-accelerator-utils";
3
- import type { Frontmatter } from '@config';
4
- import { fetchPages } from "@util/PageQueries";
5
-
6
- type BannerImage = { src: string; alt: string } | null;
7
- type AuthorList = {
8
- image: BannerImage | null;
9
- writers: MarkdownInstance<Record<string, any>>[];
10
- };
11
-
12
- export async function getAuthors () {
13
- const authors = await PostQueries.getPages(fetchPages, PostFiltering.isAuthor);
14
- return authors;
15
- }
16
-
17
- export async function getAuthorList (frontmatter: Frontmatter) {
18
- const authors = await getAuthors();
19
-
20
- const result: AuthorList = {
21
- image: null,
22
- writers: [],
23
- };
24
-
25
- (frontmatter.authors ?? []).forEach((a) => {
26
- const matches = authors.filter((x) => x.frontmatter.id == a);
27
-
28
- if (matches.length == 0) {
29
- console.warn("Unknown author", a);
30
- }
31
-
32
- if (matches.length > 1) {
33
- console.warn("Multiple authors with id", a);
34
- }
35
-
36
- if (matches.length == 1) {
37
- result.writers.push(matches[0]);
38
- if (result.image == null) {
39
- result.image = matches[0].frontmatter.bannerImage;
40
- }
41
- }
42
- });
43
-
44
- return result;
45
- }