Skip to content

Text

Get the text content of the target URL

text.js
import createClient from 'microlink.io'

const microlink = createClient()

const code = async ({ url, html }) => {
  const condenseWhitespace = require('condense-whitespace')
  const { Readability } = require('@mozilla/readability')
  const { JSDOM, VirtualConsole } = require('jsdom')

  const dom = new JSDOM(html, {
    url,
    virtualConsole: new VirtualConsole()
  })

  const reader = new Readability(dom.window.document)
  const { textContent } = reader.parse()
  return condenseWhitespace(textContent)
}

const text = (url, props) => microlink.function(url, code, props)

const { value } = await text('https://geohot.github.io/blog/jekyll/update/2023/04/26/a-person-of-compute.html')

console.log(value)