0.4.1 • Published 3 years ago

@siteone/seo-toolbar v0.4.1

Weekly downloads
2
License
MIT
Repository
-
Last release
3 years ago

SEO toolbar

Widget for managing meta tags. Build on top of react-jsonschema-form

Default Widgets and Fields

Usage

Simply install latest stable version of @siteone/seo-toolbar

yarn add @siteone/seo-toolbar

There are two components exported as Seo Toolbar with slightly different API:

1) SeoToolbarExtended

Convenient export for minimal setup. Generates rjsf schema from data object for you and selects corresponding field widgets, labels and descriptions. But lacks sophisticated customization.

import { SeoToolbarExtended } from '@siteone/seo-toolbar'

const data = {
  title: 'Some test page title',
  sitemapChangefreq: 'DAILY',
  description: 'SEO friendly page description',
  robotsFollow: true,
}
const onSubmit = data => alert(JSON.stringify(data, null, 2))

export default function Toolbar() {
  return (
    <SeoToolbarExtended
      data={data}
      onSubmit={onSubmit}
    />
  )
}

2) SeoToolbar

Allows complex setup but requires deeper understanding of rjsf

For easier use, @siteone/seo-toolbar also exports transformObjectToSchema and generateUiSchema for generating basic settins. These functions generates JSON schema with predefined form labels, descriptions and uiSchema with widgets for your data.

Note that it form labels, descriptions, select options and widgets are only applied to standardized SeoToolbarData

Other data will also work but may not look exactly how you desire.

For that case, you may consider using more customized Seo Toolbar

import SeoToolbar, { transformObjectToSchema, generateUiSchema } from '@siteone/seo-toolbar'

const data = {
  title: 'Some test page title',
  sitemapChangefreq: 'DAILY',
  description: 'SEO friendly page description',
  robotsFollow: true,
}
const onSubmit = data => alert(JSON.stringify(data, null, 2))

const schema = transformObjectToSchema(data)
const uiSchema = generateUiSchema(schema)

export default function Toolbar() {
  return (
    <SeoToolbar
      schema={schema}
      onSubmit={onSubmit}
      uiSchema={uiSchema}
    />
  )
}

If you want to have more control, here's how to achieve the same result as above without utility functions

import SeoToolbar from '@siteone/seo-toolbar'

const data = {
  title: 'Some test page title',
  sitemapChangefreq: 'DAILY',
  description: 'SEO friendly page description',
  robotsFollow: true,
}
const onSubmit = data => alert(JSON.stringify(data, null, 2))

const schema = {
  type: 'object',
  properties: {
    title: {
      type: 'string',
      default: 'Some test page title',
      title: 'Title',
    },
    sitemapChangefreq: {
      type: 'string',
      default: 'DAILY',
      enum: [ 'ALWAYS', 'HOURLY', 'DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY', 'NEVER' ],
      title: 'Sitemap (changefreq)',
      description: 'Jak často má Google reindexovat tuto stránku? (je to jen hint, ne příkaz)',
    },
    description: {
      type: 'string',
      default: 'SEO friendly page description',
      title: 'Description',
    },
    robotsFollow: {
      type: 'boolean',
      default: true,
      title: 'Robots (follow): mají vyhledávače nasledovat odkazy na této stránce?',
    },
  }
}
const uiSchema = {
  description: {
    'ui:widget': 'textarea',
  },
}

export default function Toolbar() {
  return (
    <SeoToolbar
      schema={schema}
      onSubmit={onSubmit}
      uiSchema={uiSchema}
    />
  )
}

Customizing Send button

By default, submit button with basic caption and styling is applied. But what if you need a little customization?

import { SeoToolbarExtended } from '@siteone/seo-toolbar'

const data = {
  title: 'Some test page title',
  sitemapChangefreq: 'DAILY',
  description: 'SEO friendly page description',
  robotsFollow: true,
}
const onSubmit = data => alert(JSON.stringify(data, null, 2))

export default function Toolbar() {
  return (
    <SeoToolbarExtended
      data={data}
      onSubmit={onSubmit}
    >
        <button type={'reset'}>Reset</button>
        <button type={'submit'}>Send</button>
    </SeoToolbarExtended>
  )
}

It's only important to use type="submit" so that onSubmit function is mapped properly

Remember to import this package on non user-facing pages so that is does not get into your main bundle, or load it asynchronously. This package contains @rjsf/core package which is quite hefty

Documentation

You can use all props from @rjsf/core on both SeoToolbarExtended and SeoToolbar.

import { SeoToolbarExtended } from '@siteone/seo-toolbar'

PropTypeDefaultRequiredDescription
dataSeoToolbarDataInitial data from which the rjsf schema will be constructed.
onSubmit(data: SeoToolbarData) => voidFunction called after form is submitted
titlesObject<String, String>If you want to override default form labels for data. Object keys must match data keys
requiredArrayRequired fields. Strings must match data keys
titleStringTitle of the form group. By default represented by a legend element inside a fieldset

import SeoToolbar from '@siteone/seo-toolbar'

PropTypeDefaultRequiredDescription
schemaObjectJSON schema
onSubmit(data: SeoToolbarData) => voidFunction called after form is submitted

Input Data

type SeoToolbarData = {
  uri?: String,
  title?: String,
  keywords?: String,
  description?: String,
  robotsIndex?: Boolean,
  robotsFollow?: Boolean,
  robotsArchive?: Boolean,
  robotsSnippet?: Boolean,
  sitemapChangefreq?: 'ALWAYS' | 'HOURLY' | 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'YEARLY' | 'NEVER',
  sitemapPriority?: '1.0' | '0.9' | '0.8' | '0.7' | '0.6' | '0.5' | '0.4' | '0.3' | '0.2' | '0.1' | '0.0',
  updateDatetime?: String,
  note?: String
}

Development

This package uses storybook for development and examples

Check it outwith:

yarn install && yarn dev

Build & Deployment

This package uses microbundle package for bundling. Run basic build with

yarn build
0.4.1

3 years ago

0.4.0

3 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago