mirror of
https://github.com/System-End/site.git
synced 2026-04-19 19:45:07 +00:00
Fix url encoding error on build
This commit is contained in:
parent
8de9f8318c
commit
8c228ab10b
5 changed files with 25 additions and 14 deletions
|
|
@ -31,12 +31,17 @@ async function getReadmeData(url) {
|
|||
export const getOnboardProject = async name => {
|
||||
// this is not performant to call all projects every time, but we're doing it for now while things load quickly enough
|
||||
// TODO: Speed this up
|
||||
const project = (await getAllOnboardProjects()).find(p => p.name === name)
|
||||
const readmeData = await getReadmeData(project.readmeURL)
|
||||
try {
|
||||
const project = (await getAllOnboardProjects()).find(p => p.name === name)
|
||||
const readmeData = await getReadmeData(project.readmeURL)
|
||||
|
||||
const result = { ...project, readmeData }
|
||||
const result = { ...project, readmeData }
|
||||
|
||||
return result
|
||||
return result
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export default async function handler(req, res) {
|
||||
|
|
|
|||
|
|
@ -9,12 +9,17 @@ import {
|
|||
import fs from 'fs'
|
||||
|
||||
export const gerberToSvg = async gerberURL => {
|
||||
const data = await fetch(gerberURL).then(res => res.arrayBuffer())
|
||||
const data = await fetch(gerberURL).then(res => {
|
||||
return { status: res.status, arrayBuffer: res.arrayBuffer()}
|
||||
})
|
||||
if (data.status !== 200) {
|
||||
return { status: data.status, error: 'Failed to fetch gerber file' }
|
||||
}
|
||||
const files = []
|
||||
const zip = new JSZip()
|
||||
|
||||
const zippedData = await new Promise((resolve, _reject) => {
|
||||
zip.loadAsync(data).then(resolve, e => {
|
||||
zip.loadAsync(data.arrayBuffer).then(resolve, e => {
|
||||
console.error(e)
|
||||
resolve({
|
||||
files: {} // TODO: actually handle this error (bad or nonexistent gerber.zip)
|
||||
|
|
|
|||
|
|
@ -13,5 +13,8 @@ export default async function handler(req, res) {
|
|||
return res.status(404).json({ status: 404, error: 'Invalid file' })
|
||||
}
|
||||
const svg = await gerberToSvg(parsed_url)
|
||||
if (svg.error) {
|
||||
return res.status(svg.status).send(svg.error)
|
||||
}
|
||||
return res.status(200).send(svg.top)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,11 +94,9 @@ const BoardPage = ({ project }) => {
|
|||
position: 'relative'
|
||||
}}
|
||||
>
|
||||
<Link as="a" href="/onboard/gallery" sx={{ color: 'white' }}>
|
||||
<Heading as="h1" variant="title" sx={{ textAlign: 'center' }}>
|
||||
{project.name}
|
||||
</Heading>
|
||||
</Link>
|
||||
<Heading as="h1" variant="title" sx={{ textAlign: 'center' }}>
|
||||
{project.name}
|
||||
</Heading>
|
||||
<Text as="p" variant="subtitle" sx={{ textAlign: 'center' }}>
|
||||
by {project?.readmeData?.frontmatter?.github_handle}
|
||||
</Text>
|
||||
|
|
@ -209,11 +207,11 @@ const BoardPage = ({ project }) => {
|
|||
}
|
||||
|
||||
export async function getStaticPaths(_context) {
|
||||
const projects = await getAllOnboardProjects()
|
||||
const projects = (await getAllOnboardProjects()).slice(0, 5)
|
||||
const paths = projects.map(project => {
|
||||
return {
|
||||
params: {
|
||||
slug: encodeURIComponent(project.name)
|
||||
slug: project.name
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export default function Index({ projects, itemCount }) {
|
|||
)
|
||||
}
|
||||
|
||||
export async function getStaticProps(_context) {
|
||||
export async function getStaticProps() {
|
||||
const allProjects = await getAllOnboardProjects()
|
||||
const data = allProjects.slice(0, 10)
|
||||
const projects = []
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue