Skip to content

Commit

Permalink
fix: assets copy
Browse files Browse the repository at this point in the history
  • Loading branch information
zce committed Dec 9, 2023
1 parent deb1a5e commit baf4ab1
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default async function Home() {
<Link href={`/posts/${post.slug}`}>
<h2>{post.title}</h2>
</Link>
<p>{post.summary}</p>
<p>{post.excerpt}</p>
<p>{post.tags.join(', ')}</p>
</article>
))}
Expand Down
2 changes: 2 additions & 0 deletions examples/nextjs/app/posts/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Image from 'next/image'
import { notFound } from 'next/navigation'

import { getPosts } from '#site/content'
Expand Down Expand Up @@ -37,6 +38,7 @@ export default async function PostPage({ params }: PostProps) {
<article className="prose dark:prose-invert py-6">
<h1 className="mb-2">{post.title}</h1>
{post.description && <p className="mt-0 text-xl text-slate-700 dark:text-slate-200">{post.description}</p>}
{post.cover && <Image src={post.cover} alt={post.title} placeholder="blur" />}
<hr className="my-4" />
<div className="prose" dangerouslySetInnerHTML={{ __html: post.content }}></div>
</article>
Expand Down
1 change: 1 addition & 0 deletions examples/nextjs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module.exports = {
// othor next config here...
webpack: config => {
config.watchOptions.ignored = /content/
config.plugins.push(new VeliteWebpackPlugin())
return config
}
Expand Down
2 changes: 1 addition & 1 deletion src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const processAsset = async <T extends true | undefined = undefined>(
})

const src = baseUrl + name
assets.set(name, from)
assets.set(name, path)

if (isImage !== true) return src as T extends true ? Image : string

Expand Down
8 changes: 3 additions & 5 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ export const load = async (config: Config, path: string, schema: Schema, changed
path = normalize(path)
if (changed != null && path !== changed && loaded.has(path)) {
// skip file if changed file not match
logger.log(`skipped load '${path}', using previous loaded`)
// logger.log(`skipped load '${path}', using previous loaded`)
return loaded.get(path)!
}

const begin = performance.now()

const file = new VFile({ path })
loaded.set(path, file)

Expand Down Expand Up @@ -94,7 +92,7 @@ export const load = async (config: Config, path: string, schema: Schema, changed
})
)

logger.log(`loaded '${path}' with ${parsed.length} records`, begin)
// logger.log(`loaded '${path}' with ${parsed.length} records`)
file.result = isArr ? parsed : parsed[0]
return file
}
Expand Down Expand Up @@ -125,8 +123,8 @@ const resolve = async (config: Config, changed?: string): Promise<Record<string,
}
const begin = performance.now()
const paths = await glob(pattern, { cwd: root, absolute: true, onlyFiles: true, ignore: ['**/_*'] })
logger.log(`resolve ${paths.length} files matching '${pattern}'`, begin)
const files = await Promise.all(paths.map(path => load(config, path, schema, changed)))
logger.log(`resolve ${paths.length} files matching '${pattern}'`, begin)
resolved.set(name, files)
return [name, files]
})
Expand Down
2 changes: 1 addition & 1 deletion src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const outputAssets = async (dest: string, assets: Map<string, string>): P
return
}
await copyFile(from, join(dest, name))
logger.log(`copied '${name}' from '${from}'`)
// logger.log(`copied '${name}' from '${from}'`)
emitted.set(name, from)
count++
})
Expand Down

0 comments on commit baf4ab1

Please sign in to comment.