• Stars
    star
    364
  • Rank 113,122 (Top 3 %)
  • Language
    HTML
  • License
    MIT License
  • Created over 4 years ago
  • Updated about 2 months ago

Reviews

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

Repository Details

Embed a file from GitHub repository just like GitHub Gist.

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

More Repositories

1

news-recommendation

Implementations of some methods in news recommendation.
Python
232
star
2

hnuthesis

湖南大学硕士学位论文 LaTeX 模板
TeX
51
star
3

DKN

An implementation of DKN (Deep Knowledge-Aware Network for News Recommendation) in PyTorch.
Python
48
star
4

USTC-choose-course

中科大教务系统刷课 Python 小脚本。
Python
23
star
5

Greedy-Snake-Verilog

Greedy Snake game on Nexys 4 DDR with Verilog.
Verilog
17
star
6

RecHub

A library for GNN-based recommendation system.
Python
16
star
7

LSEC-GNN

16
star
8

USTC-grade-notification

USTC 新教务系统成绩通知脚本。
Python
13
star
9

handwriting-go-away

Handwriting text generator.
Vue
13
star
10

noname

无名杀(仿三国杀)
JavaScript
9
star
11

Jiaguomeng-Assist

《家国梦》辅助脚本,能够自动收集金币、升级建筑、运输货物、点击商店中的红包和相册。
Python
8
star
12

pdf-image-binarization

Binarize all images in a scanned PDF file. 扫描版 PDF 黑白化/二值化。
Python
7
star
13

ucas-checkin

中国科学院大学开学报到提醒小工具。
Python
7
star
14

reflower

Reflow a PDF file for e-readers like Kindle.
Python
7
star
15

cloud-clipboard

Sync your clipboard across devices.
HTML
6
star
16

idiom-solitaire

Hackergame 2019 成语接龙题解
Python
6
star
17

ustc-cas-secret

利用 USTC CAS 给同学展示密信(使用场景示例:你是助教,给学生自助查分)
Python
5
star
18

bib-helper

User scripts for quickly copying BibTeX records in Google Scholar and DBLP.
JavaScript
4
star
19

USTC-grade-query

USTC 快速查成绩。
Python
3
star
20

fused-pointpillars

Python
3
star
21

USTC-academic-report

Get email notifications of new academic reports.
Python
3
star
22

HAN

An implementation of HAN (Hierarchical Attention Networks for Document Classification) in PyTorch.
Python
2
star
23

bank-management-system

A simple bank management system in Vue.js and Flask. (USTC course project)
Vue
2
star
24

USTC-tools

USTC 工具集合。
1
star
25

ros-detection

CMake
1
star
26

Base64-Encoder-Verilog

使用 Verilog 在 Nexys 4 DDR 上完成流水线 CPU 后连接键盘、显示器、编写汇编程序实现的 Base64 编码器。
Verilog
1
star
27

vm-sync

Python
1
star