Skip to content

Conversation

clemensv
Copy link
Contributor

@clemensv clemensv commented Jan 4, 2023

This PR adds three options for siteConfig (but does not touch the settings UI just yet):

  <EnableRewritingHashtagsToCategoryLinks>false</EnableRewritingHashtagsToCategoryLinks>
  <EnableRewritingBareLinksToEmbeddings>false</EnableRewritingBareLinksToEmbeddings>
  <EnableRewritingBareLinksToIcons>false</EnableRewritingBareLinksToIcons>
  • EnableRewritingHashtagsToCategoryLinks - finds all occurrences of #hashtag in the HTML plaintext and wraps them with links to the category page.
  • EnableRewritingHashtagsToCategoryLinks - finds all bare links (unwrapped links in teh plain text) and those links which are wrapped in an tag but where the text is the same as the href, and tries to embed the content they point to. That is first tried with oEmbed (the list of known sites with oembed support is embedded from https://oembed.com/providers.json for the time being and can be updated like any config file), and if oEmbed is not supported, the function tries to obtain the Open Graph embedding or the Twitter card information.
  • EnableRewritingBareLinksToIcons - finds any remaining bare links, and wraps them in with a link icon rather than leaving them bare.

The generated Twitter Card and Open Graph embeddings use "opengraph-" prefixed CSS class names as can be seen with this example:

<div class="opengraph-preview">
    <div class="opengraph-preview-site">
          <a class="opengraph-preview-link"
            href="https://www.wsj.com/articles/tesla-stock-falls-more-than-12-posting-worst-drop-in-over-two-years-11672783776"><img
                class="opengraph-preview-site-icon" src="https://s.wsj.net/media/wsj_launcher-icon-0-75x.png"> The Wall
            Street Journal</a></div><a class="opengraph-preview-link"
        href="https://www.wsj.com/articles/tesla-stock-falls-more-than-12-posting-worst-drop-in-over-two-years-11672783776"><img
            class="opengraph-preview-image" src="https://images.wsj.net/im-696241/social">
        <div class="opengraph-preview-info">
            <h3 class="opengraph-preview-title">Tesla Stock Falls 12%, Posting Worst Drop in Over Two Years</h3>
            <p class="opengraph-preview-description">Wall Street resets 2023 vehicle-delivery expectations after last
                year’s numbers fell short.</p>
        </div>
    </a>
</div>

The implementation is done in a new service.

@poppastring
Copy link
Owner

@clemensv Will review and merge in a couple of days.

@shanselman
Copy link
Collaborator

shanselman commented Jan 6, 2023

Looks like this caches the emdeds at runtime but does the work every page view? So if you startup cold, you're gonna do some real work as each new page gets rendered, right? and it really needs caching to be on. Just checking that I understand it

@poppastring
Copy link
Owner

@clemensv 👍🏿

@poppastring poppastring merged commit ddb8c8d into poppastring:main Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants