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

@takeshape/routing

v11.10.0

Published

`@takeshape/routing` is a module designed to be used on the frontend of a site generated with [TakeShape](https://www.takeshape.io). It is library agnostic so it can be used with React, Vue, etc.

Downloads

3,667

Readme

@takeshape/routing

@takeshape/routing is a module designed to be used on the frontend of a site generated with TakeShape. It is library agnostic so it can be used with React, Vue, etc.

Installation

npm install --save @takeshape/routing

Routing

The route function is used to generate links on the client side. It allows you to create links to your static site with content fetched from the TakeShape GraphQL API. It's especially useful when building out dynamic search or taxonomy pages.

route is a curried function which consumes the following params

  • config - Object - The tsg.yml config object use yaml-loader to import it
  • routeName - String - The name of the desired route
  • content - Object - An object containing the properties referenced in the route string

tsg.yml

templatePath: src/templates
staticPath: static
buildPath: build

routes:
  post:
    path: /blog/:title/
    template: pages/posts/individual.html

search-result-link.jsx

import {route as createRoute} from '@takeshape/routing';
import config from '../tsg.yml';

const route = createRoute(config);

export default function SearchResultLink({content}) {
  return <a href={route(content._contentTypeName, content)}>{content.title}</a>;
}

where the content prop would be:

{
  "_contentTypeName": "post",
  "title": "How TakeShape Routing Works"
}

Rendered HTML:

<a href="/blog/how-@takeshape/routing-works">How TakeShape Routing Works</a>

Image URLs

getImageUrl converts asset paths into URLs suitable for use in an <img> tag.

import {getImageUrl} from '@takeshape/routing';

<img src={getImageUrl('/my/image/path')}/>

<img src={getImageUrl('/my/image/path', {w: 300, h: 250})}/> // image resized to 300x250

TakeShape uses Imgix as its image CDN. Imgix provides rich suite of image manipulation capatbilities that are accessible using the second argument of getImageUrl. See their docs for all the possibilites!

Asset URLs

Not all assets in TakeShape are images and sometimes you just want a simple download link. Use getAssetUrl in this case.

import {getAssetUrl} from '@takeshape/routing';

<a href={getAssetUrl('/my/asset/path')} download>
  Download Me
</a>;