url#UrlWithStringQuery TypeScript Examples

The following examples show how to use url#UrlWithStringQuery. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ghost-normalize.ts    From next-cms-ghost with MIT License 6 votes vote down vote up
normalizePost = async (post: PostOrPage, cmsUrl: UrlWithStringQuery | undefined, basePath?: string): Promise<GhostPostOrPage> => {
  if (!cmsUrl) throw Error('ghost-normalize.ts: cmsUrl expected.')
  const rewriteGhostLinks = withRewriteGhostLinks(cmsUrl, basePath)

  const processors = [rewriteGhostLinks, rewriteRelativeLinks, syntaxHighlightWithPrismJS, rewriteInlineImages]

  let htmlAst = rehype.parse(post.html || '')
  for (const process of processors) {
    htmlAst = await process(htmlAst)
  }

  const toc = tableOfContents(htmlAst)

  // image meta
  const url = post.feature_image
  const dimensions = await imageDimensions(url)

  // author images
  const authors = await createNextProfileImagesFromAuthors(post.authors)

  return {
    ...post,
    authors,
    htmlAst,
    featureImage: (url && dimensions && { url, dimensions }) || null,
    toc,
  }
}
Example #2
Source File: ghost-normalize.ts    From next-cms-ghost with MIT License 6 votes vote down vote up
withRewriteGhostLinks =
  (cmsUrl: UrlWithStringQuery, basePath = '/') =>
  (htmlAst: Node) => {
    visit(htmlAst, { tagName: `a` }, (node: LinkElement) => {
      if (!node.properties || !node.properties.href) return
      const href = urlParse(node.properties.href)
      if (href.protocol === cmsUrl.protocol && href.host === cmsUrl.host) {
        node.properties.href = basePath + href.pathname?.substring(1)
      }
    })

    return htmlAst
  }
Example #3
Source File: customHttpClient.ts    From javascript-opensdk with Apache License 2.0 5 votes vote down vote up
// Override the private "options_" field of the base HttpClient
  options_!: UrlWithStringQuery;