Giter Site home page Giter Site logo

semasaf / gatsby-remark-link-beautify Goto Github PK

View Code? Open in Web Editor NEW

This project forked from talaxy009/gatsby-remark-link-beautify

0.0 0.0 0.0 4.59 MB

A gatsby plugin to beautify links by previewing them

License: MIT License

JavaScript 79.73% CSS 20.27%

gatsby-remark-link-beautify's Introduction

gatsby-remark-link-beautify

npm version

A gatsby plugin to beautify links by previewing them.

中文文档

✨ Features

This plugin has two main features:

  • It adds a screenshot of the link's target page to the link's tooltip. When hovering over the link it will show the screenshot.
  • It embeds card with the link's target website information in the page. It only does this in the situation below.

The example below are using the twitter-card themes.

example

🚚 Installation

npm install gatsby-remark-link-beautify

or

yarn add gatsby-remark-link-beautify

This plugin requires gatsby-transformer-remark or gatsby-plugin-mdx.

🔦 Usage

  1. Enable the plugin in your gatsby-config.js

    If you're using gatsby-transformer-remark:

    // In your gatsby-config.js
    plugins: [
        {
            resolve: `gatsby-transformer-remark`,
            options: {
                plugins: [`gatsby-remark-link-beautify`],
            },
        },
    ];

    or

    // In your gatsby-config.js
    plugins: [
        {
            resolve: `gatsby-transformer-remark`,
            options: {
                plugins: [
                    {
                        resolve: `gatsby-remark-link-beautify`,
                        options: {
                            // your options here
                        },
                    },
                ],
            },
        },
    ];

    If you're using gatsby-plugin-mdx:

    // In your gatsby-config.js
    plugins: [
        {
            resolve: `gatsby-plugin-mdx`,
            options: {
                gatsbyRemarkPlugins: [
                    `gatsby-remark-link-beautify`
                ],
            },
        },
    ];

    or

    // In your gatsby-config.js
    plugins: [
        {
            resolve: `gatsby-plugin-mdx`,
            options: {
                gatsbyRemarkPlugins: [
                    {
                        resolve: `gatsby-remark-link-beautify`,
                        options: {
                            // your options here
                        },
                    },
                ],
            },
        },
    ];
  2. Load the plugin's CSS

    // In your gatsby-browser.js
    import 'gatsby-remark-link-beautify/themes/notion.css';

    There are two themes available: notion.css and twitter-card.css. Choose your preferred theme or just load a custom one.

After that, you can use the plugin in two ways:

LinkPreview

Using link in markdown as normal:

[Gatsby](https://www.gatsbyjs.org/) is a free and open source framework for developing blazing fast websites and apps.

Then the plugin will add a screenshot of the link's target page to the link's tooltip. When hovering over the link it will show the screenshot.

LinkCard

Using link in markdown with the delimiter in a single line:

This is the Github repository:

[$card](https://github.com/gatsbyjs/gatsby/)

Then the plugin will embed a card with the link's target website information in the page.

🔧 Options

Name Type Default Description
delimiter string $card Title of the link to create a card
timeout number 30000 Default timeout(ms) for puppeteer
enableLinkPreview boolean true Whether to generate preview images or not
screenshotQuality number 80 The quality of the screenshot images in %
showFavicon boolean true Whether to show the favicon or not
browserNumer number 3 Number of browsers launched
puppeteerLaunchArgs array [] Arguments for puppeteer launch
error object {title: 'Not Found Site'} Default config when error

About browserNumer

browserNumer is the number of browsers launched. This plugin will open 5 tabs per browser at most, so 15 pages can be handled at the same time in default. It is recommended to set browserNumer depending on the size of your memory.

About puppeteerLaunchArgs

puppeteerLaunchArgs will be passed into puppeteer.launch as args arguments, where you can configure puppeteer launch parameters directly.

🚑️ Troubleshooting

Gatsby Cloud

Since Gatsby Cloud does not support any custom binaries or WASM packages like Puppeteer (see Gatsby issue 20970 and Gatsby issue 31839). So projects that rely on this plugin may have unpredictable problems (e.g., errors, timeouts) when building on Gatsby Cloud, please choose to remove this plugin or migrate your project to another service that supports Puppeteer (e.g. Netlify).

sharp

Version 1.2.x and 2.0.x of this plugin will use the sharp to resize screenshots. According to the gatsby-plugin-sharp documentation, it might cause some issues when there are multiple incompatible versions of the sharp dependency in different packages. If you encounter such issues, please update the dependencies according to the official documentation mentioned above.

better solution: It is recommended to use the 2.1.0 or higher version of this plugin. Which no longer relies on sharp, but calls the method of the official plugin gatsby-plugin-sharp to process screenshots.

💡 Inspiration

This plugin is inspired by gatsby-remark-link-preview, and added some of my thoughts. Such as customizing the component's style, don't show the error message on the card if fetch meta data failed (because the SEO of some websites may not be perfect) and previewing all links with the screenshot. Due to excessive changes, I decided to make a new plugin.

Thanks to @lichin-lin and @JaeYeopHan

gatsby-remark-link-beautify's People

Contributors

talaxy009 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.