diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2831c93..03133d7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -49,6 +49,7 @@ jobs: validate-blog: if: startsWith(github.head_ref, 'blog/') + needs: [build, lint, typecheck] runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 @@ -57,11 +58,9 @@ jobs: node-version-file: .node-version cache: npm - run: npm ci - - run: npm run validate-blog - - workin + - run: git diff --name-only | xargs npm run validate-blog -- update-blogmeta: - if: startsWith(github.head_ref, 'blog/') needs: [validate-blog] permissions: pages: write @@ -73,12 +72,12 @@ jobs: node-version-file: .node-version cache: npm - run: npm ci - - run: git diff --name-only | xargs npx ts-node --esm ./tools/update-blogmeta.ts + - run: git diff --name-only | xargs npm run update-blogmeta -- - run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" git add . - git commit -m "[Bot] Update Blog Meta" + git commit -m "[Bot] Update blog meta" git push origin ${{github.head_ref}} deploy: diff --git a/.vscode/settings.json b/.vscode/settings.json index 2296e09..e90ef3d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,5 @@ "editor.formatOnSave": true, "editor.formatOnPaste": true, "editor.defaultFormatter": "esbenp.prettier-vscode", - "prettier.documentSelectors": ["**/*.astro"], - "svg.preview.background": "transparent" + "prettier.documentSelectors": ["**/*.astro"] } diff --git a/package.json b/package.json index de1b451..ca38648 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "typecheck": "astro check && tsc --noEmit", "lint": "prettier --check \"./**/*.{ts,tsx,astro,json}\"", "format": "prettier --write \"./**/*.{ts,tsx,astro,json}\"", - "validate-blog": "git diff --name-only | xargs npx ts-node --esm tools/validate-blog.ts" + "validate-blog": "ts-node --esm tools/validate-blog.ts", + "update-blogmeta": "ts-node --esm tools/update-blogmeta.ts" }, "dependencies": { "@astrojs/check": "^0.3.1", diff --git a/src/assets/icons/blog/default_user.svg b/src/assets/icons/blog/default_user.svg new file mode 100644 index 0000000..f0a80fa --- /dev/null +++ b/src/assets/icons/blog/default_user.svg @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/components/blog/icon/AuthorIcon.astro b/src/components/blog/icon/AuthorIcon.astro index 43bccf6..2e93e91 100644 --- a/src/components/blog/icon/AuthorIcon.astro +++ b/src/components/blog/icon/AuthorIcon.astro @@ -6,35 +6,35 @@ type Props = CollectionEntry<'authors'>['data'] & { size: number } const { size, ...author } = Astro.props -const image = author.image - ? author.image - : author.github - ? ({ - type: 'external-url', - url: `https://github.com/${author.github}.png`, - } as const) - : undefined +const image = + author.image.type === 'svg' && + author.image.name === 'default_user' && + author.github + ? ({ + type: 'external-url', + url: `https://github.com/${author.github}.png`, + } as const) + : author.image --- { - image && - (image.type === 'svg' ? ( - - ) : image.type === 'external-url' ? ( - - ) : ( - unreachable(image) - )) + image.type === 'svg' ? ( + + ) : image.type === 'external-url' ? ( + + ) : ( + unreachable(image) + ) } diff --git a/src/content/config.ts b/src/content/config.ts index 465d721..6ec3304 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -42,7 +42,7 @@ const authorsCollection = defineCollection({ url: z.string().url(), }), ]) - .optional(), + .default({ type: 'svg', name: 'default_user' }), }), }) diff --git a/src/pages/blog/authors/[slug]/index.astro b/src/pages/blog/authors/[slug]/index.astro index fb50cd4..5f523dd 100644 --- a/src/pages/blog/authors/[slug]/index.astro +++ b/src/pages/blog/authors/[slug]/index.astro @@ -4,6 +4,7 @@ import BlogTitle from '@/components/blog/BlogTitle.astro' import AuthorAboutSection from '@/components/blog/author/AuthorAboutSection.astro' import AuthorIcon from '@/components/blog/icon/AuthorIcon.astro' import BlogLayout from '@/layouts/BlogLayout.astro' +import { unreachable } from '@/utils/unreachable' import { getCollection } from 'astro:content' export async function getStaticPaths() { const authorEntries = await getCollection('authors') @@ -16,13 +17,15 @@ export async function getStaticPaths() { const { author } = Astro.props const blogEntries = await getCollection('blogs') const ogpPath = - author.data.image === undefined && author.data.github !== undefined + author.data.image.type === 'svg' && + author.data.image.name === 'default_user' && + author.data.github ? `https://github.com/${author.data.github}.png` - : author.data.image?.type === 'svg' + : author.data.image.type === 'svg' ? `/author/${author.id}/ogp.png` - : author.data.image?.type === 'external-url' + : author.data.image.type === 'external-url' ? author.data.image.url - : undefined + : unreachable(author.data.image) const isShowAboutSection = author.data.description || author.data.github --- @@ -35,13 +38,9 @@ const isShowAboutSection = author.data.description || author.data.github summarySize={ogpPath === undefined ? undefined : 'summary'} > - { - (author.data.github || author.data.image) && ( - - - - ) - } + + + {isShowAboutSection && }
diff --git a/src/pages/blog/authors/[slug]/ogp.png.ts b/src/pages/blog/authors/[slug]/ogp.png.ts index 3da9e7b..fc951bc 100644 --- a/src/pages/blog/authors/[slug]/ogp.png.ts +++ b/src/pages/blog/authors/[slug]/ogp.png.ts @@ -6,7 +6,12 @@ export async function getStaticPaths() { const authors = await getCollection('authors') return authors - .filter((author) => author.data.image?.type === 'svg') + .filter( + (author) => + author.data.image.type !== 'svg' || + author.data.image.name !== 'default_user' || + !author.data.github, + ) .map((author) => ({ params: { slug: author.id }, props: { author },