Skip to content

A Contentful Plugin to replace images created in the markdown editor with SEO-friendly HTML img tags that include alt, height, width, and title attributes

Notifications You must be signed in to change notification settings

polygon-io/contentful-markdown-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Background

This Contentful app was created to extend the default markdown editor. Markdown is the preferred way to write content for most developers, however, it has some limitations that make it difficult to keep written content SEO-friendly. To display images in an SEO-friendly way, you need to know the natural height and width of the image so that you can calculate aspect ratio. Knowing the aspect ratio up front (before the image is actually loaded) allows you to reserve the proper amount of space for the image before it loads to avoid shifting content. When embedding media into a markdown field in Contentful, even though it has the image dimensions, it does not include them because markdown doesn't support it. When a user embeds media in the markdown editor, this plugin replaces the markdown syntax for the image with an html img tag that includes the height and width of the image to the values from the media file. All html is valid markdown, so this is allowed.

Changes

The Markdown Editor has been forked from https://github.com/contentful/field-editors/tree/master/packages/markdown/src and some small changes have been made to MarkdownActions insertAssetsWithConfirmation to transform the inserted media into an image tag with height and width dimensions instead of a markdown image

This project was bootstrapped with Create Contentful App.

Available Scripts

In the project directory, you can run:

npm start

Creates or updates your app definition in Contentful, and runs the app in development mode. Open your app to view it in the browser.

The page will reload if you make edits. You will also see any lint errors in the console.

npm run build

Builds the app for production to the build folder. It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes. Your app is ready to be deployed!

npm run upload

Uploads the build folder to contentful and creates a bundle that is automatically activated. The command guides you through the deployment process and asks for all required arguments. Read here for more information about the deployment process.

npm run upload-ci

Similar to npm run upload it will upload your app to contentful and activate it. The only difference is
that with this command all required arguments are read from the environment variables, for example when you add the upload command to your CI pipeline.

For this command to work, the following environment variables must be set:

  • CONTENTFUL_ORG_ID - The ID of your organization
  • CONTENTFUL_APP_DEF_ID - The ID of the app to which to add the bundle
  • CONTENTFUL_ACCESS_TOKEN - A personal access token

Libraries to use

To make your app look and feel like Contentful use the following libraries:

Using the contentful-management SDK

In the default create contentful app output, a contentful management client is passed into each location. This can be used to interact with Contentful's management API. For example

  // Use the client
  cma.locale.getMany({}).then((locales) => console.log(locales))

Visit the contentful-management documentation to find out more.

Learn More

Read more and check out the video on how to use the CLI.

Create Contentful App uses Create React App. You can learn more in the Create React App documentation and how to further customize your app.

About

A Contentful Plugin to replace images created in the markdown editor with SEO-friendly HTML img tags that include alt, height, width, and title attributes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published