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

gatsby-images-grid

v0.1.0

Published

Gatsy Images Grid =================

Downloads

3

Readme

Gatsy Images Grid

Integrates React Images Grid with beautiful React Images carousel.

Screenshot

Demo: https://kirill-konshin.github.io/images-grid/as-images/.

Installation

This component requires Gatsby Plugin MDX!

yarn install gatsby-images-grid
# or
npm install gatsby-images-grid

Usage

First of all, import styles. To do that create or update file garsby-browser.js:

import 'react-images-grid/src/styles.css';

As images

The easiest way to use gallery is to wrap a number of images (for example in the blog post) with ImagesGallery. Images in this example are places right near the blog entry's markdown:

---
title: "As Images"
date: "2020-02-08T00:00:00.000Z"
description: "Gallery of images defined in MDX"
featuredImage: ./Image-04.jpg
---

This mode allows to give each image a meaningful title.

<ImagesGallery>

![Streets of Toronto](Image-01.jpg)
![University](Image-02.jpg)
![Museum](Image-03.jpg)
![Niagara in the night](Image-04.jpg)
![Niagara](Image-05.jpg)
![Niagara, view from the car](Image-06.jpg)

</ImagesGallery>

As files

This mode requires a bit more configuration but provides more automatic approach.

You will have to modify your blog post layout for like so.

Assume your normal blog post layout looks like this:

import React from 'react';
import {graphql} from 'gatsby';
import {MDXRenderer} from 'gatsby-plugin-mdx';

import {Layout} from '../components/layout';

const BlogPostTemplate = ({
    data: {
        mdx: post
    },
    location,
}) => {
    return (
        <Layout
            location={location}
            title={post.frontmatter.title}
            description={post.frontmatter.description || post.excerpt}
        >
            <h1>{post.frontmatter.title}</h1>
            <p>&nbsp;{post.frontmatter.date}</p>
            <MDXRenderer>{post.body}</MDXRenderer>
        </Layout>
    );
};

export default BlogPostTemplate;

export const pageQuery = graphql`
    query BlogPostBySlug($slug: String!, $absolutePathRegex: String!) {
        mdx(fields: {slug: {eq: $slug}}) {
            id
            excerpt(pruneLength: 160)
            body
            frontmatter {
                title
                date(formatString: "MMMM DD, YYYY")
                description
            }
        }
    }
`;

You can use technique from this issue to get all images from the blog post folder: https://github.com/gatsbyjs/gatsby/issues/11246:

import React from 'react';
import {graphql} from 'gatsby';
import {MDXRenderer} from 'gatsby-plugin-mdx';

import {Layout} from '../components/layout';

const BlogPostTemplate = ({
    data: {
        mdx: post,
+        allFile: {nodes: images = []},
    },
    location,
}) => {
    return (
        <Layout
            location={location}
            title={post.frontmatter.title}
            description={post.frontmatter.description || post.excerpt}
        >
            <h1>{post.frontmatter.title}</h1>
            <p>&nbsp;{post.frontmatter.date}</p>
-            <MDXRenderer>{post.body}</MDXRenderer>
+            <MDXRenderer images={images}>{post.body}</MDXRenderer>
        </Layout>
    );
};

export default BlogPostTemplate;

export const pageQuery = graphql`
    query BlogPostBySlug($slug: String!, $absolutePathRegex: String!) {
        mdx(fields: {slug: {eq: $slug}}) {
            id
            excerpt(pruneLength: 160)
            body
            frontmatter {
                title
                date(formatString: "MMMM DD, YYYY")
                description
            }
        }
+        # here we search for all image-like files in blog directory
+        allFile(filter: {extension: {regex: "/(jpg|jpeg|png)/"}, absolutePath: {regex: $absolutePathRegex}}) {
+            nodes {
+                name
+                childImageSharp {
+                    fixed {
+                        ...GatsbyImageSharpFixed
+                    }
+                    original {
+                        src
+                    }
+                }
+            }
+        }
    }
`;

You need to put $absolutePathRegex into context in /gatsby-node.js (for more info take a look at this issue):

exports.createPages = async ({graphql, actions}) => {
    const {createPage} = actions;

    const {
        data: {
            allMdx: {edges: posts},
        },
    } = await graphql(`
        query Blog { ... usual stuff }
    `);

    posts.forEach(
        ({
            node: {
                fileAbsolutePath,
                fields: {slug},
            },
        }) => {
            createPage({
                path: slug,
                component: path.resolve(`src/templates/blog-post.js`),
                context: {
                    slug,
                    //@see https://github.com/gatsbyjs/gatsby/issues/11246#issuecomment-612793091
                    absolutePathRegex: `/^${path.dirname(fileAbsolutePath)}/`, 
                },
            });
        },
    );
};

Now in blog entries we can use the FilesGallery:

---
title: "As files"
date: "2018-06-09T00:00:00.000Z"
description: "Gallery of files defined in template"
featuredImage: ./Image-02.jpg
---

This mode just dumps all image-like files from current directory as gallery.

import {FilesGallery} from 'gatsby-images-grid';
<FilesGallery>{props.images}</FilesGallery>

With layout (optional)

If you don't want to import galleries in each blog post you can use MDXProvider.

Follow MDX plugin documentation to create a layout with MDXProvider from @mdx-js/react (which you've installed for gatsby-plugin-mdx): https://www.gatsbyjs.org/packages/gatsby-plugin-mdx/#mdxprovider and https://www.gatsbyjs.org/packages/gatsby-plugin-mdx/#default-layouts.

Add FilesGallery and ImagesGallery from gatsby-images-grid:

// src/components/layout.js

import React from 'react';
import {MDXProvider} from '@mdx-js/react';
import {FilesGallery, ImagesGallery} from 'gatsby-images-grid';

const components = {FilesGallery, ImagesGallery};

export const Layout = ({children, title}) => (
    <MDXProvider components={components}>
        <div style={{maxWidth: '1200px', margin: '0 auto'}}>
            <h1>{title}</h1>
            <div>{children}</div>
        </div>
    </MDXProvider>
);

export default Layout;