2022-07-01 23:12:47 +02:00
|
|
|
import fs from 'node:fs'
|
|
|
|
import { fileURLToPath } from 'node:url'
|
2022-02-22 21:19:42 +01:00
|
|
|
|
2022-03-14 09:09:46 +01:00
|
|
|
import ejs from 'ejs'
|
|
|
|
import date from 'date-and-time'
|
|
|
|
import { Parcel } from '@parcel/core'
|
2022-02-22 21:19:42 +01:00
|
|
|
|
2022-03-14 09:09:46 +01:00
|
|
|
export const render = async (resume) => {
|
|
|
|
const themeIndexURL = new URL('./theme/index.ejs', import.meta.url)
|
|
|
|
const themeBuildURL = new URL('./theme/index.html', import.meta.url)
|
|
|
|
const indexHTMLURL = new URL('./dist/index.html', import.meta.url)
|
|
|
|
const themeBuildPath = fileURLToPath(themeBuildURL)
|
|
|
|
const html = await ejs.renderFile(fileURLToPath(themeIndexURL), {
|
2022-02-22 21:19:42 +01:00
|
|
|
date,
|
|
|
|
locals: {
|
|
|
|
...resume
|
|
|
|
}
|
|
|
|
})
|
2022-03-14 09:09:46 +01:00
|
|
|
await fs.promises.writeFile(themeBuildURL, html, { encoding: 'utf-8' })
|
2022-02-22 21:19:42 +01:00
|
|
|
const bundler = new Parcel({
|
|
|
|
entries: themeBuildPath,
|
|
|
|
source: themeBuildPath,
|
|
|
|
mode: 'production',
|
|
|
|
defaultConfig: '@parcel/config-default'
|
|
|
|
})
|
|
|
|
await bundler.run()
|
2022-03-14 09:09:46 +01:00
|
|
|
return await fs.promises.readFile(indexHTMLURL, { encoding: 'utf-8' })
|
2022-02-22 21:19:42 +01:00
|
|
|
}
|