Skip to content

Commit

Permalink
デフォルトユーザーアイコンを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
miyaji255 committed Nov 24, 2023
1 parent c112c1f commit 85117ae
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 49 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/assets/icons/blog/default_user.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 28 additions & 28 deletions src/components/blog/icon/AuthorIcon.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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' ? (
<Icon
name={image.name}
alt={`${image.name} のアイコン`}
class="aspect-square rounded-full"
height={size}
width={size}
isBlog
/>
) : image.type === 'external-url' ? (
<img
src={image.url}
height={size}
width={size}
class="aspect-square rounded-full"
/>
) : (
unreachable(image)
))
image.type === 'svg' ? (
<Icon
name={image.name}
alt={`${image.name} のアイコン`}
class="aspect-square rounded-full"
height={size}
width={size}
isBlog
/>
) : image.type === 'external-url' ? (
<img
src={image.url}
height={size}
width={size}
class="aspect-square rounded-full"
/>
) : (
unreachable(image)
)
}
2 changes: 1 addition & 1 deletion src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const authorsCollection = defineCollection({
url: z.string().url(),
}),
])
.optional(),
.default({ type: 'svg', name: 'default_user' }),
}),
})

Expand Down
21 changes: 10 additions & 11 deletions src/pages/blog/authors/[slug]/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
---
Expand All @@ -35,13 +38,9 @@ const isShowAboutSection = author.data.description || author.data.github
summarySize={ogpPath === undefined ? undefined : 'summary'}
>
<BlogTitle title={author.data.name} background="white">
{
(author.data.github || author.data.image) && (
<Fragment slot="icon">
<AuthorIcon {...author.data} size={95} />
</Fragment>
)
}
<Fragment slot="icon">
<AuthorIcon {...author.data} size={93} />
</Fragment>
</BlogTitle>
{isShowAboutSection && <AuthorAboutSection author={author.data} />}
<main class="flex flex-col h-full">
Expand Down
7 changes: 6 additions & 1 deletion src/pages/blog/authors/[slug]/ogp.png.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down

0 comments on commit 85117ae

Please sign in to comment.