Skip to content

Commit ae2381f

Browse files
committed
feat: load creation author
1 parent 35e65ec commit ae2381f

File tree

5 files changed

+143
-3
lines changed

5 files changed

+143
-3
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ node_modules
22
.DS_Store
33
docs/.vitepress/dist
44
docs/data/creations.json
5-
docs/public/creations
5+
docs/public/creations
6+
docs/data/authors.json
7+
docs/public/authors

docs/.vitepress/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { defineConfig } from 'vitepress'
22
import { generateSidebar } from './generateSidebar'
33
import { getLatestBridgeVersion } from './latestBridgeVersion'
4+
import { loadAuthors } from './loadAuthors'
45
import { loadCreations } from './loadCreations'
56

67
// const latestBridgeVersion = await getLatestBridgeVersion()
78

89
loadCreations()
10+
loadAuthors()
911

1012
const base = '/docs/'
1113

docs/.vitepress/loadAuthors.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import fs from 'fs'
2+
import { dirname, join } from 'path'
3+
import matter from 'gray-matter'
4+
import sharp from 'sharp'
5+
6+
export function loadAuthors() {
7+
const authorDirEntries = fs.readdirSync(
8+
join(process.cwd(), 'docs', 'authors'),
9+
{ withFileTypes: true }
10+
)
11+
const authors: any = {}
12+
13+
for (const entry of authorDirEntries) {
14+
if (!entry.isDirectory()) continue
15+
16+
const creationDir = join(process.cwd(), 'docs/authors', entry.name)
17+
const creationPath = join(creationDir, 'index.md')
18+
19+
const str = fs.readFileSync(creationPath, 'utf8')
20+
let frontMatter: matter.GrayMatterFile<string>
21+
try {
22+
frontMatter = matter(str)
23+
} catch (err) {
24+
throw new Error(
25+
`File ${creationPath} has invalid frontmatter! ${err.message}`
26+
)
27+
}
28+
29+
authors[frontMatter.data.id] = {
30+
...frontMatter.data,
31+
image: '/' + join(`authors/${entry.name}`, frontMatter.data.image),
32+
}
33+
34+
// Copy thumbnails to public folder
35+
const outputPath = join(
36+
process.cwd(),
37+
'docs/public/authors',
38+
entry.name,
39+
frontMatter.data.image
40+
)
41+
fs.mkdirSync(dirname(outputPath), { recursive: true })
42+
43+
// Convert image to avif with sharp
44+
sharp(join(creationDir, frontMatter.data.image))
45+
.resize({ width: 80, height: 80 })
46+
.avif()
47+
.toFile(outputPath.replace(/\.(jpg|png)$/, '.avif'))
48+
49+
// Copy normal image over as a fallback
50+
fs.copyFileSync(join(creationDir, frontMatter.data.image), outputPath)
51+
}
52+
53+
fs.writeFileSync(
54+
join(process.cwd(), 'docs', 'data/authors.json'),
55+
JSON.stringify(authors)
56+
)
57+
}

docs/.vitepress/theme/components/CreationCard.vue

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<script setup lang="ts">
2+
import { computed } from 'vue'
23
import { withBase } from 'vitepress'
34
import VPButton from 'vitepress/client/theme-default/components/VPButton.vue'
5+
import authors from '../../../data/authors.json'
6+
47
export interface ICreation {
58
title: string
69
excerpt: string
@@ -9,14 +12,16 @@ export interface ICreation {
912
download: string
1013
}
1114
15+
console.log(authors, props.creation.author, authors[props.creation.author])
1216
const props = defineProps<{
1317
creation: ICreation
1418
}>()
19+
const author = computed(() => authors[props.creation.author])
1520
</script>
1621

1722
<template>
1823
<div class="card">
19-
<picture :alt="`Thumbnail of ${creation.title}`">
24+
<picture>
2025
<source
2126
:srcset="
2227
withBase(creation.image).replace(/\.(jpg|png)$/, '.avif')
@@ -32,6 +37,38 @@ const props = defineProps<{
3237

3338
<div class="content">
3439
<h1>{{ creation.title }}</h1>
40+
41+
<div class="author">
42+
<picture>
43+
<source
44+
:srcset="
45+
withBase(author.image).replace(
46+
/\.(jpg|png)$/,
47+
'.avif'
48+
)
49+
"
50+
type="image/avif"
51+
/>
52+
<source :srcset="withBase(author.image)" />
53+
<img
54+
class="author-logo"
55+
:src="withBase(author.image)"
56+
:alt="`Logo of ${author.title}`"
57+
/>
58+
</picture>
59+
60+
<div class="author-name">
61+
<span>{{ author.title }}</span>
62+
<span class="author-position">{{ author.position }}</span>
63+
</div>
64+
</div>
65+
66+
<div class="tag-list">
67+
<span class="tag" v-for="tag in creation.tags">
68+
#{{ tag }}
69+
</span>
70+
</div>
71+
3572
<p>{{ creation.excerpt }}</p>
3673
</div>
3774

@@ -49,6 +86,7 @@ const props = defineProps<{
4986

5087
<style scoped>
5188
.card {
89+
text-align: left;
5290
display: flex;
5391
flex-flow: column;
5492
background: var(--vp-c-bg-soft);
@@ -72,4 +110,45 @@ h1 {
72110
justify-content: flex-end;
73111
padding: 12px;
74112
}
113+
114+
.author {
115+
display: flex;
116+
align-items: center;
117+
background: var(--vp-c-bg);
118+
border-radius: 12px;
119+
padding: 4px 8px;
120+
margin: 8px 0;
121+
}
122+
.author-logo {
123+
height: 32px;
124+
border-radius: 100%;
125+
margin-right: 12px;
126+
}
127+
.author-name {
128+
display: flex;
129+
flex-direction: column;
130+
justify-items: center;
131+
}
132+
.author-position {
133+
font-size: 12px;
134+
color: var(--vp-c-text-soft);
135+
margin-top: -4px;
136+
}
137+
138+
.tag-list {
139+
display: flex;
140+
gap: 4px;
141+
flex-wrap: wrap;
142+
justify-content: flex-start;
143+
align-items: center;
144+
margin-bottom: 16px;
145+
}
146+
.tag {
147+
background: var(--vp-c-bg);
148+
padding: 4px 8px;
149+
border-radius: 12px;
150+
flex: 1;
151+
text-align: center;
152+
white-space: nowrap;
153+
}
75154
</style>

docs/creations/seaside-story/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: 'Seaside Story'
33
image: './main.jpg'
44
author: 'gamemode-one'
55
excerpt: 'Live out your own peaceful ocean adventure!'
6-
tags: [ocean, fishing, relaxing, bridge-v2]
6+
tags: [ocean, fishing, relaxing]
77
download: 'https://www.minecraft.net/en-us/marketplace/pdp?id=5c7cd39e-9903-477b-b013-1b6b6d2bd9ab'
88
---
99

0 commit comments

Comments
 (0)