Giter Site home page Giter Site logo

houminz / emgithub Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yusanshi/emgithub

0.0 1.0 0.0 218 KB

Embed a file from GitHub repository just like GitHub Gist.

Home Page: https://emgithub.com

License: MIT License

JavaScript 47.40% HTML 52.60%

emgithub's Introduction

emgithub

https://emgithub.com/

Embed a file from GitHub repository just like GitHub Gist.

Demo: https://yusanshi.com/posts/2019-12-17/emgithub/ (scroll to the bottom of the page).

Get started

There are two ways to use the service:

  1. Go to https://emgithub.com/ and paste the URL.
  2. Open a file in GitHub and simply add "em" before "github.com" in the address bar.

ProTip

  • Support permanent links to a file or a code snippet (use # to slice code).

  • Specify TAB width with ?ts=. Note when used together with code slicing, you should combine them like this: ?ts=2#L4-L12.

  • Support Markdown (*.md) and Jupyter Notebook (*.ipynb) rendering.

  • If the preview in https://emgithub.com/ is OK but it looks strange when embedded into the target web page, chances are that the styles are overridden by the target web page. In this case, you may need to write some CSS styles to fix it (and !important may be needed). Below is the skeleton for embedding which may be helpful for writing CSS styles.

    <div class="emgithub-container">
      <div class="emgithub-file">
        <div class="file-data">
          <div class="code-area">
            <!-- for regular code embedding -->
            <a class="copy-btn">Copy</a>
            <pre>
              <code>
                <!-- code content -->
            </code>
          </pre>
          </div>
    
          <div class="html-area markdown-body">
            <!-- for Markdown/Jupyter Notebook  -->
          </div>
        </div>
    
        <div class="file-meta">
          <!-- footer -->
        </div>
      </div>
    </div>

Development

You can modify the code and test it by launching an HTTP server in the project directory.

  1. Launch an HTTP server.

    git clone https://github.com/yusanshi/emgithub
    cd emgithub
    python -m http.server 8086
  2. Make the changes.

  3. Visit http://localhost:8086/404.html.

    Don't be confused by the "404". It is how the "adding em in the address bar" works: after adding the "em", the HTTP server (provided by GitHub Pages) can't find the file so it renders 404.html. Then in the 404 page, the target file is extracted from the URL.

Create your own emgithub

You may want to create your own emgithub for some reasons, like:

  • To fit your personal needs.
  • For security. Say if https://emgithub.com/ is hacked...
  • For stability. There may be some breaking changes with https://emgithub.com/ (although I'm trying to avoid this, e.g., when there are major changes, embed-v2.js, embed-v3.js ... are used. In this way, the former embeddings are not influenced).

To do this, you can use either GitHub Pages or your own web server.

Use GitHub Pages

If you choose to use GitHub Pages just like https://emgithub.com/ does, you can fork the project and remove the CNAME file. Then go to Your repository - Settings - GitHub Pages to setup a custom domain or simply use username.github.io.

Use your own web server

If you choose to use your own web server, such as Apache and Nginx, the most important thing to do is to configure the server to serve 404.html for a not-found request.

For example, here is a simple configuration without HTTPS for Nginx:

server {
  listen 80;
  listen [::]:80;

  server_name your_domain.com;

  root /var/www/project_directory;

  location / {
    try_files $uri /404.html;
  }
}

Credits

emgithub's People

Contributors

yusanshi avatar cfurrow avatar fantasticmao avatar chipoglesby avatar mjmacleod avatar weirane avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.