How to use nast-util-from-notionapi - 2 common examples

To help you get started, we’ve selected a few nast-util-from-notionapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dragonman225 / notablog / src / render-post.js View on Github external
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 => {
github dragonman225 / notablog / src / parse-table.js View on Github external
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
    }
  }

nast-util-from-notionapi

Transform Notion.so pages to NAST representation.

MIT
Latest version published 7 months ago

Package Health Score

58 / 100
Full package analysis

Popular nast-util-from-notionapi functions