1
1
mirror of https://github.com/theoludwig/theoludwig.git synced 2024-11-12 23:33:14 +01:00
.profile/jsonresume-theme-custom/index.js

29 lines
908 B
JavaScript
Raw Normal View History

import fs from 'fs'
import { fileURLToPath } from 'url'
2022-02-22 21:19:42 +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
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
}
})
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()
return await fs.promises.readFile(indexHTMLURL, { encoding: 'utf-8' })
2022-02-22 21:19:42 +01:00
}