mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-20 03:14:06 -06:00
Merge 59b836bd79 into e6cc9ba368
This commit is contained in:
commit
a1dd294ca7
@ -261,35 +261,35 @@ async function rebuild(changes: ChangeEvent[], clientRefresh: () => void, buildD
|
|||||||
.map((file) => file.content),
|
.map((file) => file.content),
|
||||||
)
|
)
|
||||||
|
|
||||||
let emittedFiles = 0
|
const emittedFiles = await Promise.all(
|
||||||
for (const emitter of cfg.plugins.emitters) {
|
cfg.plugins.emitters.map(async (emitter) => {
|
||||||
// Try to use partialEmit if available, otherwise assume the output is static
|
const emitFn = emitter.partialEmit ?? emitter.emit
|
||||||
const emitFn = emitter.partialEmit ?? emitter.emit
|
const emitted = emitFn(ctx, processedFiles, staticResources, changeEvents)
|
||||||
const emitted = await emitFn(ctx, processedFiles, staticResources, changeEvents)
|
if (emitted === null) {
|
||||||
if (emitted === null) {
|
return 0
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Symbol.asyncIterator in emitted) {
|
|
||||||
// Async generator case
|
|
||||||
for await (const file of emitted) {
|
|
||||||
emittedFiles++
|
|
||||||
if (ctx.argv.verbose) {
|
|
||||||
console.log(`[emit:${emitter.name}] ${file}`)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
if (Symbol.asyncIterator in emitted) {
|
||||||
// Array case
|
let emittedFiles = 0
|
||||||
emittedFiles += emitted.length
|
// Async generator case
|
||||||
if (ctx.argv.verbose) {
|
for await (const file of emitted) {
|
||||||
for (const file of emitted) {
|
emittedFiles++
|
||||||
console.log(`[emit:${emitter.name}] ${file}`)
|
if (ctx.argv.verbose) {
|
||||||
|
console.log(`[emit:${emitter.name}] ${file}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return emittedFiles
|
||||||
|
} else {
|
||||||
|
// Array case
|
||||||
|
return await Promise.all(
|
||||||
|
(await emitted).map((file) => {
|
||||||
|
console.log(`[emit:${emitter.name}] ${file}`)
|
||||||
|
}),
|
||||||
|
).then((files) => files.length)
|
||||||
}
|
}
|
||||||
}
|
}),
|
||||||
}
|
)
|
||||||
|
const sumFiles = emittedFiles.reduce((a, b) => a + b)
|
||||||
console.log(`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince("rebuild")}`)
|
console.log(`Emitted ${sumFiles} files to \`${argv.output}\` in ${perf.timeSince("rebuild")}`)
|
||||||
console.log(styleText("green", `Done rebuilding in ${perf.timeSince()}`))
|
console.log(styleText("green", `Done rebuilding in ${perf.timeSince()}`))
|
||||||
changes.splice(0, numChangesInBuild)
|
changes.splice(0, numChangesInBuild)
|
||||||
clientRefresh()
|
clientRefresh()
|
||||||
|
|||||||
@ -1,7 +1,14 @@
|
|||||||
import { QuartzEmitterPlugin } from "../types"
|
import { QuartzEmitterPlugin } from "../types"
|
||||||
import { i18n } from "../../i18n"
|
import { i18n } from "../../i18n"
|
||||||
import { unescapeHTML } from "../../util/escape"
|
import { unescapeHTML } from "../../util/escape"
|
||||||
import { FullSlug, getFileExtension, isAbsoluteURL, joinSegments, QUARTZ } from "../../util/path"
|
import {
|
||||||
|
FilePath,
|
||||||
|
FullSlug,
|
||||||
|
getFileExtension,
|
||||||
|
isAbsoluteURL,
|
||||||
|
joinSegments,
|
||||||
|
QUARTZ,
|
||||||
|
} from "../../util/path"
|
||||||
import { ImageOptions, SocialImageOptions, defaultImage, getSatoriFonts } from "../../util/og"
|
import { ImageOptions, SocialImageOptions, defaultImage, getSatoriFonts } from "../../util/og"
|
||||||
import sharp from "sharp"
|
import sharp from "sharp"
|
||||||
import satori, { SatoriOptions } from "satori"
|
import satori, { SatoriOptions } from "satori"
|
||||||
@ -109,16 +116,20 @@ export const CustomOgImages: QuartzEmitterPlugin<Partial<SocialImageOptions>> =
|
|||||||
getQuartzComponents() {
|
getQuartzComponents() {
|
||||||
return []
|
return []
|
||||||
},
|
},
|
||||||
async *emit(ctx, content, _resources) {
|
async emit(ctx, content, _resources): Promise<FilePath[]> {
|
||||||
const cfg = ctx.cfg.configuration
|
const cfg = ctx.cfg.configuration
|
||||||
const headerFont = cfg.theme.typography.header
|
const headerFont = cfg.theme.typography.header
|
||||||
const bodyFont = cfg.theme.typography.body
|
const bodyFont = cfg.theme.typography.body
|
||||||
const fonts = await getSatoriFonts(headerFont, bodyFont)
|
const fonts = await getSatoriFonts(headerFont, bodyFont)
|
||||||
|
return Promise.all(
|
||||||
for (const [_tree, vfile] of content) {
|
content
|
||||||
if (vfile.data.frontmatter?.socialImage !== undefined) continue
|
.filter(
|
||||||
yield processOgImage(ctx, vfile.data, fonts, fullOptions)
|
([_tree, vfile]) =>
|
||||||
}
|
vfile.data.frontmatter?.socialImage === undefined &&
|
||||||
|
vfile.data.filePath !== undefined,
|
||||||
|
)
|
||||||
|
.map(([_tree, vfile]) => processOgImage(ctx, vfile.data, fonts, fullOptions)),
|
||||||
|
)
|
||||||
},
|
},
|
||||||
async *partialEmit(ctx, _content, _resources, changeEvents) {
|
async *partialEmit(ctx, _content, _resources, changeEvents) {
|
||||||
const cfg = ctx.cfg.configuration
|
const cfg = ctx.cfg.configuration
|
||||||
|
|||||||
@ -13,14 +13,14 @@ export async function emitContent(ctx: BuildCtx, content: ProcessedContent[]) {
|
|||||||
|
|
||||||
log.start(`Emitting files`)
|
log.start(`Emitting files`)
|
||||||
|
|
||||||
let emittedFiles = 0
|
|
||||||
const staticResources = getStaticResourcesFromPlugins(ctx)
|
const staticResources = getStaticResourcesFromPlugins(ctx)
|
||||||
await Promise.all(
|
const emittedFiles = await Promise.all(
|
||||||
cfg.plugins.emitters.map(async (emitter) => {
|
cfg.plugins.emitters.map(async (emitter) => {
|
||||||
try {
|
try {
|
||||||
const emitted = await emitter.emit(ctx, content, staticResources)
|
const emitted = emitter.emit(ctx, content, staticResources)
|
||||||
if (Symbol.asyncIterator in emitted) {
|
if (Symbol.asyncIterator in emitted) {
|
||||||
// Async generator case
|
// Async generator case
|
||||||
|
let emittedFiles = 0
|
||||||
for await (const file of emitted) {
|
for await (const file of emitted) {
|
||||||
emittedFiles++
|
emittedFiles++
|
||||||
if (ctx.argv.verbose) {
|
if (ctx.argv.verbose) {
|
||||||
@ -29,22 +29,27 @@ export async function emitContent(ctx: BuildCtx, content: ProcessedContent[]) {
|
|||||||
log.updateText(`${emitter.name} -> ${styleText("gray", file)}`)
|
log.updateText(`${emitter.name} -> ${styleText("gray", file)}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return emittedFiles
|
||||||
} else {
|
} else {
|
||||||
// Array case
|
// Array case
|
||||||
emittedFiles += emitted.length
|
return (
|
||||||
for (const file of emitted) {
|
await Promise.all(
|
||||||
if (ctx.argv.verbose) {
|
(await emitted).map((file) => {
|
||||||
console.log(`[emit:${emitter.name}] ${file}`)
|
if (ctx.argv.verbose) {
|
||||||
} else {
|
console.log(`[emit:${emitter.name}] ${file}`)
|
||||||
log.updateText(`${emitter.name} -> ${styleText("gray", file)}`)
|
} else {
|
||||||
}
|
log.updateText(`${emitter.name} -> ${styleText("gray", file)}`)
|
||||||
}
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
).length
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
trace(`Failed to emit from plugin \`${emitter.name}\``, err as Error)
|
trace(`Failed to emit from plugin \`${emitter.name}\``, err as Error)
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
const sumFiles = emittedFiles.reduce((a, b) => a + b)
|
||||||
log.end(`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince()}`)
|
log.end(`Emitted ${sumFiles} files to \`${argv.output}\` in ${perf.timeSince()}`)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user