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

github-embed

v1.0.1

Published

Github embedder

Downloads

197

Readme

github-embed npm version

The tool allows to embed code from Github on a webpage.

Demo

Usage

CommonJS

npm install --save github-embed babel-polyfill
require('babel-polyfill');
const githubEmbed = require('github-embed');
githubEmbed('.element', settings);

CSS is placed at node_modules/github-embed/npm/css/github-embed.css.

Direct use

Bundled (downloadable) version and the demo of the tool lives at gh-pages branch.

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.23.0/polyfill.min.js"></script>
<script src="github-embed.min.js"></script>
<script>
    githubEmbed('.element', settings);
</script>

API

githubEmbed function accepts two arguments: an element where embedding block will be mount (a selector, a node, jQuery instance etc) and settings object.

Settings object should include the following properties:

  • repo: STRING a name of a repository whose files will be embedded
  • owner: STRING an owner of the repo
  • ref: STRING a branch, a tag or commit SHA
  • embed: ARRAY a list of embedded files
    • path: STRING - a path to embedded file relative to the root of the repo
    • type: STRING - a type of file you want to embed (a programming language)
    • label: STRING - what to display in navigation. By default it's a name of embedded file
    • active: BOOLEAN - is the item shown by default
    • repo: STRING - a name of a repository where current file lives (in case if you want to embed a file from another repo)
    • owner: STRING - an owner of a repo where current file lives (in case if you want to embed a file from another repo)
    • ref: STRING - a branch, a tag or commit SHA of a repo where current file lives (in case if you want to embed a file from another branch or repo)

There is one more thing: you can add to your embedding list any webpage. It could be useful if you want to show how does your web tool works. You need to set type option as "htmlpage" and assign webpage URL to "url" property

Example:

githubEmbed('#root', {
    "owner": "finom",
    "repo": "github-embed",
    "ref": "master",
    "embed": [
        {
            "type": "htmlpage",
            "label": "Embedded HTML page",
            "url": "http://example.com/"
        },
        {
    		"type": "js",
    		"label": "Webpack config",
    		"path": "webpack.config.js"
    	}, {
    		"type": "js",
    		"label": "Entry point",
    		"path": "src/index.js"
    	}, {
    		"type": "json",
    		"path": ".gh-embed.json"
    	}
    ]
});

Remote settings

In case if you want to embed your code on few places and you don't want to break something when a file path is changed (eg you have renamed app.js to index.js) you can store embedding settings remotely inside a file next to embedded files. It allows to get your embedding always up to date and you'll need to modify it when paths are changed.

githubEmbed('.embed', 'https://github.com/finom/github-embed/blob/master/.gh-embed.json');

Usually I call settings file .gh-embed.json.

It should contain valid JSON object with data described above. The only difference: you don't need to specify owner, repo and ref because these properties will be extracted from settings URL.

{
    "embed": [
        {
            "type": "htmlpage",
            "label": "Embedded HTML page",
            "url": "http://example.com/"
        },
        {
    		"type": "js",
    		"label": "Webpack config",
    		"path": "webpack.config.js"
    	}, {
    		"type": "js",
    		"label": "Entry point",
    		"path": "src/index.js"
    	}, {
    		"type": "json",
    		"path": ".gh-embed.json"
    	}
    ]
}