0.1.8 โ€ข Published 4 years ago

@francesc/gatsby-plugin-multilang-twitter-cards v0.1.8

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

gatsby-plugin-multilang-twitter-cards ๐Ÿ‡บ๐Ÿ‡ณ๐Ÿ“‡

This project is forked from gatsby-remark-twitter-cards, which in turn was derived from gatsby-remark-social-cards

The main goal of this fork is to make it compatible with multi-languguage sites using gatsby-plugin-intl. To achieve this goal, a field named lang must be defined in all markdown nodes.

gatsby-plugin-multilang-twitter-cards in action

gatsby-plugin-multilang-twitter-cards is a Gatsby plugin that allows you to create individual open graph twitter card images at build time for inclusion in your site's SEO metadata. It generates cards as JPGs with embedded text in the recommended size of 1200px x 630px.

It uses the wasm-twitter-card library under the hood: by using Rust libraries compiled to WebAssembly, we can work around some of the limitations of the most popular dependency-free image editing library for Node.js, jimp.

It can be added to your plugins in gatsby-config.js like so:

  plugins: [
    // ...
    {
      resolve: `@francesc/gatsby-plugin-multilang-twitter-cards`,
      options: {
        localizedTitles: {en: 'English title', ca: 'Tรญtol catalร '}, // website titles - required
        localizedAuthors: {en: 'English author', ca: 'Autor catalร '}, // website author names - optional
        defaultLanguage: 'en', // default language (defaults to 'en')
        separator: '|', // defaults to '|'
        background: require.resolve('./content/assets/base.jpg'), // optional path to 1200x630px file or hex code, defaults to black (#000000)
        fontColor: '#ffffff', // defaults to white (#ffffff)
        titleFontSize: 96, // defaults to 96
        subtitleFontSize: 60, // defaults to 60
        fontStyle: 'monospace', // defaults to 'monospace'
        fontFile: require.resolve('./content/assets/someFont.ttf'), // optional path to a custom TTF font - will override fontStyle
        cardFileName: 'twitter-card.jpg', // optional file name used with social cards - defaults to 'twitter-card-jpg'
      },
    },
  ],

Plugin Options

OptionRequiredTypeDefault value
localizedTitlesโœ”object{en: 'Untitled'}
localizedAuthorsโœ”object{en: 'Mr. Gatsby'}
defaultLanguageโœ”stringen
separatorโœ”string (character that separates title and author)"|"
backgroundโœ”hex or file path"#000000"
fontColorโœ”hex"#ffffff"
titleFontSizeโœ”int96
subtitleFontSizeโœ”int60
fontStyleโœ”"monospace" or "sans-serif"monospace
fontFileโœ”path to TTF font file
cardFileNameโœ”file name used when creating social cardstwitter-card.jpg

The images will be saved in your site's /public folder, and the link to your twitter:image should be an absolute URL (something like ${siteUrl}${lang}${blogPostSlug}twitter-card.jpg) E.g. for this blog post the generated image can be found at the link https://aless.co/en/how-to-build-a-keyboard/twitter-card.jpg.

Further instructions on how to include open graph images in the metadata of your Gatsby blog can be found in the excellent documentation of the plugin that inspired this one, gatsby-remark-social-cards

Roadmap

  • Custom TTF fonts ๐ŸŽ‰
  • Monospace or sans serif font
  • Custom title font size
  • Custom subtitle font size
  • Custom font color
  • Accept path to background image
  • OR solid color background with hex code
  • Multiple languages
  • Convert the gatsby-remark plugin into a regular Gatsby plugin