Coder Social home page Coder Social logo

excalidraw / gatsby-embedder-excalidraw Goto Github PK

View Code? Open in Web Editor NEW
55.0 5.0 3.0 1.69 MB

๐Ÿคด Custom transformer to embed Excalidraw diagrams

Home Page: https://gatsby-embedder-excalidraw.netlify.app

License: MIT License

JavaScript 100.00%
excalidraw diagram embed remark gatsby embedder markdown svg gatsby-plugin

gatsby-embedder-excalidraw's Introduction

gatsby-embedder-excalidraw

This custom transformer for gatsby-remark-embedder allows you to embed Excalidraw diagrams in Markdown content simply by pasting an Excalidraw link in the source.

The code for this library is lifted from this directory in the excalidraw-blog Gatsby site. All credit for this transformer goes to those authors. I was inspired to do this when I saw Alex Luong's tweet about making this functionality into a gatsby-remark-excalidraw plugin.

Installation

npm install gatsby-embedder-excalidraw

Usage

// gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: 'gatsby-transformer-remark',
      options: {
        plugins: [
          {
            resolve: 'gatsby-remark-embedder',
            options: {
              customTransformers: [require('gatsby-embedder-excalidraw')]
            }
          }
        ]
      }
    }
  ]
};

Example

This guide will show you how to get up and running with gatsby-embedder-excalidraw in the fewest steps possible. It uses gatsby-plugin-mdx to take advantage of its awesome default behaviour of automatically creating pages based on MDX files in src/pages.

Install dependencies

First, install gatsby and its dependencies:

npm install gatsby react react-dom

Next, install gatsby-plugin-mdx and its dependencies:

npm install gatsby-plugin-mdx @mdx-js/mdx @mdx-js/react

Configure plugins

Add gatsby-plugin-mdx to your Gatsby config:

// gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: 'gatsby-plugin-mdx'
    }
  ]
};

Install the gatsby-remark-embedder plugin and this Excalidraw transformer gatsby-embedder-excalidraw:

npm install gatsby-remark-embedder gatsby-embedder-excalidraw

Add gatsby-remark-embedder as a Gatsby remark plugin for gatsby-plugin-mdx. In your gatsby-remark-embedder options, add gatsby-embedder-excalidraw as a custom transformer:

// gatsby-config.js
module.exports = {
  plugins: [
    {
-     resolve: 'gatsby-plugin-mdx'
+     resolve: 'gatsby-plugin-mdx',
+     options: {
+       gatsbyRemarkPlugins: [
+         {
+           resolve: 'gatsby-remark-embedder',
+           options: {
+             customTransformers: [require('gatsby-embedder-excalidraw')]
+           }
+         }
+       ]
+     }
    }
  ]
};

Create a drawing

Head over to Excalidraw and draw something! Once you're satisfied, you can find a shareable link to your drawing in the export dialog, accesible from the icon in the top left corner of the page.

link

Embed your drawing

Create an MDX page at src/pages/index.mdx and add a link to an Excalidraw diagram:

# Fox grab flowchart

Fox's followups after a grab depend on your opponent's DI:

https://excalidraw.com/#json=5695519967936512,sLhjTgn1_wB1iVLLquX6Fg

Voila! ๐ŸŽ‰ https://excalidraw-embed.trevorblades.com

License

MIT

gatsby-embedder-excalidraw's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar dwelle avatar excalibot avatar j-f1 avatar lipis avatar trevorblades avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

j-f1 dwelle

gatsby-embedder-excalidraw's Issues

Add to docs how to get shareable link

I didn't know that I can share my work through a link on excalidraw.

My suggestion is to add one of the following:

"To get a shareable link for your work on excalidraw, export your work and press the link icon ๐Ÿ”—"

Or
export

add this GIF

Bug Stuck on Building development bundle

Hi,

Going through the readme explanation, when adding gatsby-embedder-excalidraw to gatsbyRemarkPlugins of gatsby-plugin-mdx and running gatsby develop, the building bundle stuck and never finishes.

Reproducible example in codesandbox:

Edit Gatsby Embedder Excaildraw Bug

Also, cloning the repo (installing the dependencies etc.) and running the example will result in the same issue.

๐Ÿ› No node found for selector [aria-label='Scale 3 x']

I'm not sure if I should file here or as an issue with gatsby-plugin-mdx but after a month of not touching my site, I can't get the development bundle to build correctly and it looks like it's unhappy with the Excalidraw links.

yarn run v1.22.4
$ gatsby develop
success open and validate gatsby-configs - 0.092s
success load plugins - 4.334s
success onPreInit - 0.018s
success initialize cache - 0.022s
success copy gatsby files - 0.075s
success onPreBootstrap - 0.013s
success createSchemaCustomization - 0.005s

 ERROR #11321  PLUGIN

"gatsby-plugin-mdx" threw an error while running the onCreateNode lifecycle:

The following error appeared while processing 'https://excalidraw.com/#json=5086916491870208,sLUFfW5oMgrO3ApQwe4YQw':

No node found for selector: [aria-label='Scale 3 x']

  31 |   const createAndProcessNode = path => {
  32 |     const fileNodePromise = createFileNode(path, createNodeId, pluginOptions).then(fileNode => {
> 33 |       createNode(fileNode);
     |       ^
  34 |       return null;
  35 |     });
  36 |     return fileNodePromise;

File: node_modules/gatsby-source-filesystem/gatsby-node.js:33:7

To Reproduce

This is on my personal site on the bug-reproduce.

  1. git clone --single-branch --branch bug-reproduce https://github.com/jsjoeio/joeprevite.com.git
  2. yarn install
  3. yarn dev

Observe output

Expected

Success - everywhere!

Actual

A bunch of errors and an unhappy development bundle

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.