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

@xyfir/blog

v0.2.1

Published

A simple blog system that's easily integrated into existing sites. Markdown + React + GitHub.

Downloads

2

Readme

A customizable yet simple, GitHub-hosted, React-powered, and Markdown-supported blogging system that is easily integrated into existing sites and applications. Used by Ptorx and other projects in the Xyfir Network.

Demonstrations

Installation and Setup

Note: This package is currently in alpha, meaning its API may change significantly in the future. Backwards compatibility will be strived for, but cannot be guaranteed.

See the example directory for a working, up-to-date, example.

npm install @xyfir/blog

Then, somewhere in your React application:

import Blog from '@xyfir/blog';

// ...

<Blog
  // (optional) ID of the post being viewed
  // You'll have to handle extracting the id from the current URL based on your
  // `linkFormat` prop!
  post="group/year/month/filename"
  // (optional) Groups from the repo to allow posts from.
  // Defaults to allowing all groups.
  // A "group" is a subdirectory in the GitHub repository
  groups={['group1', 'group2']}
  // (required) GitHub repository id.
  // Example: `":user/:repo" | "Xyfir/blog-posts"`
  repository="GitHubUser/GitHubRepository"
  // (required) Format to use for blog links
  // Example: `"/blog/{{post.id}}" | "/blog?id={{post.id}}"`
  linkFormat="/blog/{{post.id}}"
  // (optional) Format to use for the page title (`<title>`).
  // The first element is for when _not_ viewing a post, and the second element
  // is for when the user _is_ viewing a post.
  // All post properties are allowed: post.id, post.author, ...
  titleFormat={['Example Blog', '{{post.title}} - Example Blog']}
  // (optional) Passed to `marked('', markedOptions)` when converting Markdown
  // to HTML. See: https://marked.js.org
  // Nothing passed by default, meaning Markdown is NOT sanitized
  markedOptions={{}}
  // (optional) Format to use for the page description
  // (`<meta name="description" content="..." >`)
  // The first element is for when _not_ viewing a post, and the second element
  // is for when the user _is_ viewing a post.
  // All post properties are allowed: post.id, post.author, ...
  descriptionFormat={[
    'The best blog in the whole wide world.',
    '{{post.description}}'
  ]}
/>;

// ...

That's pretty much it in terms of code, but you'll have to style everything yourself. Optionally, you can use the default styles which you can import from node_modules/@xyfir/blog/dist/blog.css, which pairs nicely with the GitHub Markdown styles as found in github-markdown-css.

Writing and Managing Posts

You should have a public GitHub repository created which you'll point to in <Blog>'s repository prop. The repository should have a structure that looks something like this:

some-group/
  2017/
    02/
      some-post.md
      another-post.md
    04/
      hello-world.md
  2018/
    01/
      hello-world.md
    12/
      lorem-ipsum.md
some-other-group/
  ...
posts.json

The first subdirectories within the repository are your "groups", which allow you to optionally organize things however you want. For Xyfir, we use it to organize posts by site name, since we have lots of sites but want all of our posts in a single repository. You can do whatever you want however.

Within groups, are year subdirectories, simply YYYY-formatted years. Within year subdirectories are month subdirectories, simply MM-formatted months.

Finally, within the month subdirectories are the posts themselves, which can be named anything you want but generally should be URL-friendly and contain at least part of the post's title. Post names must only be unique within the subdirectory that they reside.

posts.json allows you to make posts publicly available to the <Blog> component by adding the post's metadata to its array. The posts.json array should look something like this:

[
  {
    "id": "test/2018/07/test-2",
    "group": "test",
    "title": "Test #2",
    "author": "Bob",
    "posted": "2018-07-13",
    "description": "Lorem ipsum dolor sit amet..."
  },
  {
    "id": "test/2018/07/test-1",
    "group": "test",
    "title": "Test #1",
    "author": "Alice",
    "posted": "2018-07-12",
    "edited": "2018-07-13",
    "canonical": "https://www.xyfir.com/blog/test/2018/07/test-1"
  }
]

Order doesn't matter, but we generally recommend putting the newest posts at the top.

  • id - required - A post id is a unique identifier for each post of the following format: group/year/month/filename. Note that filename excludes the .md extension!
  • group - required - The group the post resides in.
  • title - required - The post's title.
  • author - required - The post's author.
  • posted - required - The date the post was posted. Format: YYYY-MM-DD.
  • edited - optional - The date the post was edited. Format: YYYY-MM-DD.
  • canonical - optional - The canonical link for the post if it is available at multiple locations. See Wikipedia: Canonical link element.
  • description - optional - A (typically short) description for the post.

To create, edit, or delete a post is easy: add/edit/delete the file within the repository at group/year/month/filename, and then update posts.json to reflect the changes if needed, and then commit and push your changes to the live repository. All of the blogs that point to that repository will automatically be updated upon the next page load.