Skip to content

Commit 3df5ab8

Browse files
committed
fix production build and content pull
1 parent 5c95771 commit 3df5ab8

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

.github/workflows/docker.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
name: Docker CI
22

33
on:
4-
push:
4+
workflow_run:
5+
workflows: ["Basic Checks"]
6+
types:
7+
- completed
58
branches:
69
- main
710

811
jobs:
912
build:
1013
runs-on: ubuntu-latest
14+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1115
environment: prod
1216
steps:
1317
- uses: actions/checkout@v4

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"dev": "bun run build && bun run generate_dev && bun run server_dev",
4141
"generate": "bun out/generate.js",
4242
"server": "bun out/index.js",
43-
"prod": "bun run generate && bun run server"
43+
"prod": "bun run generate && bun run server",
44+
"clean": "bun run src/public-clean-up.ts"
4445
}
4546
}

src/markdown.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function extractDescription(markdown: string): string {
5353
const lines = markdown.split('\n')
5454
for (const line of lines) {
5555
if (/^\p{L}/u.test(line)) {
56-
return this.convertToPlaintext(line)
56+
return convertToPlaintext(line)
5757
}
5858
}
5959
return ''
@@ -98,7 +98,7 @@ export function convertToHtml(markdown: string): string {
9898
<Heading
9999
depth={header.depth}
100100
text={header.text}
101-
id={this.generateId(header.text)}
101+
id={generateId(header.text)}
102102
/>
103103
)
104104
}

src/pullarticles.ts

+32-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {Octokit} from 'octokit'
55
import {Buffer} from 'buffer/'
66

77
const IGNORE_LIST: string[] = ['README.md', '.git', '.gitignore']
8+
const IMAGE_EXTENSIONS: string[] = ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp']
89

910
/**
1011
* Parse GitHub repository details from URL
@@ -34,14 +35,24 @@ function createOctokitClient(githubToken?: string): Octokit {
3435
}
3536

3637
/**
37-
* Download individual markdown file
38+
* Check if a file is an image based on its extension
39+
* @param filename Filename to check
40+
* @returns Boolean indicating if file is an image
41+
*/
42+
function isImage(filename: string): boolean {
43+
const ext = path.extname(filename).toLowerCase()
44+
return IMAGE_EXTENSIONS.includes(ext)
45+
}
46+
47+
/**
48+
* Download both markdowns or images
3849
* @param octokit Octokit client
3950
* @param owner Repository owner
4051
* @param repo Repository name
4152
* @param item File item details
4253
* @param articlesDir Destination directory
4354
*/
44-
async function downloadMarkdownFile(
55+
async function downloadFile(
4556
octokit: Octokit,
4657
owner: string,
4758
repo: string,
@@ -56,11 +67,18 @@ async function downloadMarkdownFile(
5667
})
5768

5869
// Decode file content (GitHub API returns base64 encoded content)
59-
const fileContent = Buffer.from(data.content, 'base64').toString('utf-8')
60-
70+
const fileContent = Buffer.from(data.content, 'base64')
71+
6172
const localFilePath = path.join(articlesDir, item.path)
6273
await fs.mkdir(path.dirname(localFilePath), {recursive: true})
63-
await fs.writeFile(localFilePath, fileContent)
74+
75+
if (item.name.endsWith('.md')) {
76+
// For markdown files, convert to utf-8 string before writing
77+
await fs.writeFile(localFilePath, fileContent.toString('utf-8'))
78+
} else {
79+
// For binary files like images, write the buffer directly
80+
await fs.writeFile(localFilePath, fileContent)
81+
}
6482

6583
console.log(`Downloaded: ${item.path}`)
6684
} catch (error) {
@@ -101,8 +119,11 @@ async function processRepoContents(
101119

102120
if (item.type === 'dir') {
103121
await processRepoContents(octokit, owner, repo, item.path, articlesDir)
104-
} else if (item.type === 'file' && item.name.endsWith('.md')) {
105-
await downloadMarkdownFile(octokit, owner, repo, item, articlesDir)
122+
} else if (
123+
item.type === 'file' &&
124+
(item.name.endsWith('.md') || isImage(item.name))
125+
) {
126+
await downloadFile(octokit, owner, repo, item, articlesDir)
106127
}
107128
}
108129
} catch (error) {
@@ -112,7 +133,7 @@ async function processRepoContents(
112133
}
113134

114135
/**
115-
* Pull articles from a GitHub repository
136+
* Pull articles and images from a GitHub repository
116137
* @param articlePath Destination path for articles
117138
* @param config Configuration options
118139
*/
@@ -124,7 +145,6 @@ async function pullArticles(
124145
}
125146
): Promise<void> {
126147
try {
127-
// Use environment variables if not provided
128148
const githubToken = config?.githubToken || process.env.GITHUB_TOKEN
129149
const sourceUrl = config?.sourceUrl || process.env.SOURCE
130150

@@ -139,14 +159,13 @@ async function pullArticles(
139159
const articlesDir = path.resolve(process.cwd(), articlePath)
140160
await fs.mkdir(articlesDir, {recursive: true})
141161

142-
// Start processing from root
143162
await processRepoContents(octokit, owner, repo, '', articlesDir)
144163

145-
console.log('Article pull completed successfully')
164+
console.log('Article and image pull completed successfully')
146165
} catch (error) {
147-
console.error('Error pulling articles:', error)
166+
console.error('Error pulling articles and images:', error)
148167
throw error
149168
}
150169
}
151170

152-
export default pullArticles
171+
export default pullArticles

0 commit comments

Comments
 (0)