npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-social-schema

v1.0.0-alpha1

Published

A hybrid implementation of Social Share Buttons and Structured Data.

Downloads

7

Readme

react-social-schema

A hybrid implementation of Social Share Buttons and Structured Data.

Why?

Structured data is valuable for search engines to discover information in your web application. This approach uses the structured data provided as props to create the stories used in social sharing buttons so you only have to worry about one set of data.

Features

  • Share buttons for Facebook, Twitter, Tumblr, and Pinterest

    • Live refreshing for all except Twitter.
    • Intent opens in a popup window
  • Structured Data

    • Provides data for share intents - two birds with one stone!

Install

yarn add react-social-schema

Because it's 2017. Yarn rocks.

Compatibility

Built with React v15 and Chrome 55, not yet tested elsewhere.

How to use

See ./example/MyApp.jsx


API

Container

| Props | Default Value | Description | | --- | --- | --- | | schema | not set | The schema object that will be passed down via context. | | className | "share-actions" | The class name that will be given to the container component. | | thisComponent | "div" | The HTML element or React Component that will be used as the container. |

render()

Returns the wrapper component, a <script> tag containing the JSON schema, and whatever children are passed to this component.


BaseButton

| Props | Default Value | Description | | --- | --- | --- | | buttonComponent | 'button' | Component or HTML element to use for the button. | | countComponent | 'span' | Component or HTML element to use for the count display. | | children | <FacebookIcon /> | Inner HTML for the button component. | | className | 'facebook' | For the button. | | count | null | If set, live refreshing will be disabled. | | fetchTimeoutMS | 3600 * 1000 | Interval in milliseconds to live refresh the count. |

| State | Description | | --- | --- | | count | Contains the value of the last fetched count. | | lastFetch | The timestamp (in milliseconds) of the last fetch |

setCount(count)

Updates this.state.count and this.state.lastFetch

getCount()

Returns the last known count. If this.props.count is specified (live refreshing disabled), it will return that value. If not set (live refreshing enabled) then this.state.count will be returned if the value is fresh.

Otherwise, this.updateCount will be called and this.state.count will be returned immediately.

updateCount()

This method will error out unless it is defined in classes extending from BaseButton.

countNode()

Returns the count component or HTML element with the latest fetched value.

render()

Provides default markup that can be overridden. Provides hooks to onClick


FacebookButton

onClick()

Spawns a popup for the Facebook Sharer.

getCount(): Promise

Retrieves the latest count from Facebook and resolves.


PinterestButton

onClick()

Spawns a popup for the Pinterest Sharer.

getCount(): Promise

Retrieves the latest count from Pinterest and resolves


TwitterButton

getTwitterHandle()

If specified, this will always return this.props.twitterHandle

Else, it will try to detect the handle from the schema using resolveSocial(schema, test)

onClick()

Spawns a popup for the Tweet and/or Retweet Intents. If specified, this.props.tweetID will prompt a Retweet instead of a Tweet intent.

getCount(): Promise

Immediately rejects because Twitter does not provide share counts.


TumblrButton

onClick()

Spawns a popup for the Tumblr Sharer.

getCount()

Retrieves the latest count from Tumblr and resolves.


popup.js

popup(url, inputOptions, callback)

Spawns a new popup window. If specified a callback function will be called when the popup window is closed.


selectors.js

getTitleAttribute(schema)

Returns the schema attribute designated as a story's title.

getBodyAttribute(schema)

Returns the schema attribute designated as a story's content body.

getImageAttribute(schema)

Returns the schema attribute for the most likely image, in the following order of first available:

  • schema.image
  • schema.author.image
  • schema.publisher.logo

If none of these are available, a deep search will occur for an object where @type = "ImageObject" and return the first match.

resolveSocial(schema, test)

Returns the first object in the following list where a value matches test

  • schema.author.sameAs
  • schema.publisher.sameAs
  • schema.provider.sameAs
  • schema.sameAs

Example:

resolveSocial(schema, (a) => a.indexOf('twitter.com') !== -1);


Need Help

Any pull request is warmly welcomed towards making this module better - adding additional networks, tests, or providing better compatibility.

Related