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 🙏

© 2026 – Pkg Stats / Ryan Hefner

gatsby-remark-strava

v2.0.0

Published

Gatsby remark plugin to embed Strava activities and routes by their URL

Readme

Npm Build Status Coverage Downloads PRs welcome MIT license Sponsor


Gatsby remark plugin to embed Strava activities and routes by their URL.

It works in two modes, chosen by its options:

  • Embed mode, the default, shows the official Strava embed. It needs no token and makes no request.
  • Render mode, when you give a render function, builds your own markup from the activity. The activity comes from the store of strava-sync, the one gatsby-source-strava fills, and is fetched from Strava only when it is missing.

Requires Node 22.12 or later.

Usage

  1. Download gatsby-remark-strava from the NPM registry:
npm install gatsby-remark-strava
  1. Add the plugin to your gatsby-config.js file. It must be a child plugin of gatsby-transformer-remark, or a gatsbyRemarkPlugins entry of gatsby-plugin-mdx.
module.exports = {
  plugins: [
    {
      resolve: "gatsby-transformer-remark",
      options: {
        plugins: ["gatsby-remark-strava"],
      },
    },
  ],
}
  1. Add a link to your content, alone in its paragraph:
[strava activity 3657585594 embed](https://www.strava.com/activities/3657585594)

[strava route 3350146254546787420 embed](https://www.strava.com/routes/3350146254546787420)

The link text must contain "embed" (whatever the case), so that a plain link to an activity stays a link. The URL is https://www.strava.com/activities/<id> or https://www.strava.com/routes/<id>, with an optional trailing slash or query.

Embed mode

The link becomes the placeholder of the official embed, and a small script of the plugin loads https://strava-embeds.com/embed.js on the pages that have one. The script replaces each placeholder with an iframe, also when the page is reached by a client side navigation.

<div
  class="strava-embed-placeholder"
  data-embed-type="activity"
  data-embed-id="3657585594"
></div>

Strava only shows what is public:

  • an activity needs its profile and its visibility set to Everyone,
  • a route needs to be public.

Segments are not supported.

Render mode

Give a render function that receives the activity and returns the markup. Routes keep the official embed.

module.exports = {
  plugins: [
    {
      resolve: "gatsby-plugin-mdx",
      options: {
        gatsbyRemarkPlugins: [
          {
            resolve: "gatsby-remark-strava",
            options: {
              output: "mdx",
              storeDir: ".strava",
              stravaClientId: process.env.STRAVA_CLIENT_ID,
              stravaClientSecret: process.env.STRAVA_CLIENT_SECRET,
              stravaToken: process.env.STRAVA_TOKEN,
              render: (activity) => {
                const date = new Date(activity.start_date).toLocaleDateString(
                  "en-us",
                  {year: "numeric", month: "short", day: "numeric"}
                )

                return `
                  <strava
                    id="${activity.id}"
                    name="${activity.name}"
                    distance="${activity.distance}"
                    start_date="${date}"
                    photo="${activity.photos?.primary?.urls["600"] || ""}"
                  />
                `
              },
            },
          },
        ],
      },
    },
  ],
}
  • render always receives a detailed activity, the shape of GET /activities/{id} (calories, photos.primary.urls...). The activity is read from the storeDir folder first, so a site that uses gatsby-source-strava makes no request for the activities it has stored with their details (resource_state 3).
  • The API is called, with strava-sync, for an activity that is missing from the store or that the store only holds as a summary of the list (resource_state 2). It needs stravaClientId, stravaClientSecret and stravaToken. Up to 4 requests run at once, and the activity is kept in the Gatsby cache, so the next builds do not fetch it again.
  • Without the token options, a summary of the store is passed to render as it is, with one warning, and a missing activity stays a link.
  • When gatsby-source-strava stores the list of photos, photos is that list and the summary is under photos_summary. render gets the shape of the API, with the summary back under photos.
  • Generate the token with npx strava-sync token, see the strava-sync documentation.

Usage with MDX

gatsby-plugin-mdx turns raw HTML nodes into inert <span dangerouslySetInnerHTML> elements. Set output: "mdx" to emit JSX elements instead, in both modes.

With output: "mdx", the markup returned by render must be a single JSX element, so use className instead of class and an object for style. Every tag goes through the components given to MDXProvider, so a custom tag such as <strava> can be mapped to a React component. A capitalized tag must be provided there, otherwise MDX throws.

See the remark example for the embed mode, and the mdx one for the render mode.

Options

| Option | Default | Description | | -------------------- | ----------- | ------------------------------------------------------------------------------------ | | render | | Function receiving the activity and returning the markup. It switches to render mode | | output | "html" | "html" for gatsby-transformer-remark, "mdx" for gatsby-plugin-mdx (MDX v2+) | | storeDir | ".strava" | Store folder, relative to the site, the same as the gatsby-source-strava option | | stravaClientId | | Strava application client ID, to fetch an activity missing from the store | | stravaClientSecret | | Strava application client secret | | stravaToken | | Strava token, as generated by strava-sync token | | debug | false | Logs every embed that succeeds |

A link that cannot be turned into an embed, because of a failing render or a missing activity, stays a link and logs a warning.

Migrating from 1.x

  • The iframe https://www.strava.com/activities/<id>/embed/<token> stopped displaying, Strava no longer supports it. The default is now the official embed, which needs a public activity and no token. Remove the three Strava options if you do not use render.
  • Routes links are embedded too.
  • The gatsby-remark-strava-token command is gone. Run npx strava-sync token instead, it writes the same STRAVA_CLIENT_ID, STRAVA_CLIENT_SECRET and STRAVA_TOKEN variables.
  • render is kept, and now switches to render mode. The activity is read from the gatsby-source-strava store before Strava is called, so the token is only needed for an activity that is not in it, or that it only holds as a summary. Set storeDir if you moved the store.
  • output and debug are kept. The fetched activity is cached, not the markup.
  • Node 22.12 or later is required.

Support this project