• Stars
    star
    127
  • Rank 282,790 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Embed code from Github on HTML page

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"
    	}
    ]
}

More Repositories

1

seemple

Seemple.js framework
JavaScript
872
star
2

balalaika

Tiny DOM library
JavaScript
288
star
3

tsimmes

A function for elements selection
JavaScript
226
star
4

node-direct

Allows to run server-side JavaScript files via NodeJS as easy as PHP files via Apache
JavaScript
98
star
5

vanillatree

Vanilla.js replacement of jstree
JavaScript
93
star
6

use-change

The most minimalistic React state management library on the market with zero dependencies and React.useState-like syntax
TypeScript
91
star
7

elegant-threading

A straightforward definition of multi-threaded functions for NodeJS and browser
JavaScript
61
star
8

defi

A bunch of utilities that enable accessor-based reactivity for JavaScript objects
JavaScript
50
star
9

deploy-to-git

Deploy build artifacts to a Git repository
JavaScript
46
star
10

vovk

RESTful RPC for Next.js - Transforms Next.js into a powerful REST API platform with RPC capabilities.
TypeScript
44
star
11

mongo-git-backup

A tool for making text Mongo backups on Git repos
JavaScript
39
star
12

Suitup

Simple WYSIWYG editor
JavaScript
30
star
13

check-imports

Check imports in JS files and update package.json dependencies
JavaScript
28
star
14

last-release-git

semantic-release plugin for projects that must not be published at NPM
JavaScript
26
star
15

babel-plugin-transform-es2015-modules-simple-amd

Limited transformer for ECMAScript 2015 modules (AMD)
JavaScript
26
star
16

jQuery-Gaussian-Blur

Plugin which adds Gaussian Blur effect for images
JavaScript
23
star
17

donutjs

Simplest cross-browser (VML+SVG) donut chart generator
JavaScript
23
star
18

babel-plugin-transform-es2015-modules-simple-commonjs

Limited transformer for ECMAScript 2015 modules (CommonJS)
JavaScript
19
star
19

typo.js

JavaScript
17
star
20

rebloom

Type-safe React application state library with zero setup
TypeScript
13
star
21

seemple-examples-and-tutorials

Seemple.js examples and tutorials
HTML
10
star
22

function-decorators-proposal

10
star
23

eslint-plugin-output-todo-comments

Contains single rule that warns about used warning comments and shows them as they are
JavaScript
8
star
24

Functions

This repository contains few functions that help in deciding of certain problems.
JavaScript
5
star
25

css-dot-js-loader

A Webpack loader which allows to generate static CSS code via JavaScript
JavaScript
4
star
26

babel-plugin-nofn

Experimental Babel plugin which takes function call and transpiles it to inline code
JavaScript
3
star
27

finom

3
star
28

seemple.js.org

Seemple.js website
SCSS
3
star
29

uniquestring

Simple function which generates pseudo-random string based on current timestamp and Math.random call
JavaScript
2
star
30

tailwind-to-object

Single-function library that converts Tailwind classes to CSS style objects
JavaScript
2
star
31

makeelement

A function to use it instead of document.createElement
JavaScript
2
star
32

matreshka_boilerplate

ES.next boilerplate app for Matreshka.js
JavaScript
2
star
33

fabric-browser

Fabric.js bridge with no node-specific dependencies
JavaScript
1
star
34

trading-strategies-backtest

TypeScript
1
star
35

altamoon

HTML
1
star
36

defi.js.org

The website
CSS
1
star