Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (task != null) {
const siteMeta = task.siteMeta
const templateProvider = task.templateProvider
const post = task.post
const operations = task.operations
const plugins = task.plugins
const pageID = post.id
const cachePath = post.cachePath
let nast, contentHTML
/** Fetch page. */
if (operations.doFetchPage) {
log.info(`Fetch page ${pageID}`)
nast = await getOnePageAsTree(pageID, new NotionAgent({ suppressWarning: true, verbose: false }))
fs.writeFile(cachePath, JSON.stringify(nast), (err) => {
if (err) console.error(err)
else log.info(`Cache of ${pageID} is saved`)
})
} else {
log.info(`Read page cache ${pageID}`)
let cache = await fsPromises.readFile(cachePath, { encoding: 'utf-8' })
let _nast = parseJSON(cache)
if (_nast != null) nast = _nast
else throw new Error(`Cache of ${pageID} is corrupted, delete source/notion_cache to rebuild`)
}
/** Run `beforeRender` plugins. */
log.info(`Run beforeRender plugins on ${pageID}`)
if (operations.enablePlugin) {
plugins.forEach(plugin => {
async function parseTable(notionDatabaseURL, notionAgent) {
let pageID = getPageIDFromNotionDatabaseURL(notionDatabaseURL)
let pageCollection = (await getOnePageAsTree(pageID, notionAgent))
/**
* Create map for property_name -> property_id.
* Notion uses random strings in schema to prevent probable repeated
* property names defined by user.
*/
let schemaMap = {}
for (let [key, value] of Object.entries(pageCollection.schema)) {
let propertyId = key
let propertyString = value.name
if (schemaMap[propertyString]) {
log.warn(`Duplicate column name "${propertyString}", column with id "${propertyId}" is used`)
} else {
schemaMap[propertyString] = key
}
}