Giter Club home page Giter Club logo

jekyll-github-sample's Introduction

jekyll-github-sample

Two Jekyll Liquid tags to display a code sample from a file in a public Github repo and provide a reference to it.

Install

  1. Add the gem to your Gemfile.
    gem 'jekyll_github_sample'
  2. Install.
    bundle install 
  3. Add the gem to your Jekyll _config.yml.
    plugins: 
      - jekyll_github_sample
  4. Start Jekyll.

Live Examples

A write up on my Jekyll blog including samples referencing this repo's code, meta.

github_sample Usage

{% github_sample URL_WITH_USERNAME_REPO_AND_FILE <START_LINE_NUMBER> <END_LINE_NUMBER> %}
  • URL_WITH_USERNAME_REPO_AND_FILE - the relative path to the Github repo file, prefer a file with the commitish in it so it won't change when recompiling occurs. A url to this README would be: bwillis/jekyll-github-sample/blob/a3bc9e82412d364aa76e9308ab53ff2bddaa2faf/README.md
  • START_LINE_NUMBER - (optional) number that is the first line to include (0 based)
  • END_LINE_NUMBER - (optional) number that is the last line to include, if excluded will read to end of file

One can also specify the lines to include based on markings in the file itself. This is done by invoking

{% github_sample URL_WITH_USERNAME_REPO_AND_FILE tag:TAG_NAME %}

And placing the strings [START TAG_NAME] and [END TAG_NAME] anywhere in the lines immediately before and after the content you wish to include.

github_sample_ref Usage

{% github_sample_ref URL_WITH_USERNAME_REPO_AND_FILE %}
  • URL_WITH_USERNAME_REPO_AND_FILE - the relative path to the Github repo file, prefer a file with the commitish in it so it won't change when recompiling occurs. A url to this README would be: bwillis/jekyll-github-sample/blob/a3bc9e82412d364aa76e9308ab53ff2bddaa2faf/README.md

Example Usage

This is how you would display, reference and highlight code in your Jekyll post.

{% github_sample_ref /bwillis/versioncake/989237901cb873f96df12be48cbf1239be496bd7/Appraisals %}

{% highlight ruby %}
{% github_sample /bwillis/versioncake/989237901cb873f96df12be48cbf1239be496bd7/Appraisals 0 5 %}
{% endhighlight %}

Thanks!

Thanks to all those who have helped make this really awesome:

License

Jekyll Github Sample is released under the MIT license.

jekyll-github-sample's People

Contributors

bwillis avatar dependabot[bot] avatar heedfull avatar kriation avatar michaelcurrin avatar robertwb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

jekyll-github-sample's Issues

Update for jekyll 3.1.x

It would be cool to update this for jekyll 3. Currently getting an error when I try to bundle

jekyll_github_sample was resolved to 0.1.0, which depends on
      jekyll (~> 1.0)

Liquid Exception: No such file or directory @ rb_sysopen

Hey,

using the latest version of jekyll-github-sample (v0.3.2) together with Jekyll v4.2.0 and the setup from the README (the exact same sample usages), I get this error on jekyll build:

Liquid Exception: No such file or directory @ rb_sysopen - https://raw.githubusercontent.com/bwillis/versioncake/Appraisals/ in /home/..../post.md
bundler: failed to load command: jekyll (/usr/local/lib/ruby/gems/3.0.0/bin/jekyll)
/usr/local/lib/ruby/gems/3.0.0/gems/jekyll_github_sample-0.3.2/lib/jekyll_github_sample/code_tag.rb:19:in `initialize': No such file or directory @ rb_sysopen - https://raw.githubusercontent.com/bwillis/versioncake/Appraisals/ (Errno::ENOENT)

Any hints on what the issue could be? Anyone else getting this as well? :)

Does not work on Jekyll 3.4.0

When trying to run the sample from the main page on Jekyll 3.4.0:

{% github_sample_ref /bwillis/versioncake/989237901cb873f96df12be48cbf1239be496bd7/Appraisals %}
{% highlight ruby %}
{% github_sample /bwillis/versioncake/989237901cb873f96df12be48cbf1239be496bd7/Appraisals 0 5 %}
{% endhighlight %}

It gives:

  Liquid Exception: bad value for range in /Users/anatolii/Projects/blog/src/_posts/2017-02-23-test-plugins.md
/Library/Ruby/Gems/2.0.0/gems/jekyll_github_sample-0.3.0/lib/jekyll_github_sample/code_tag.rb:25:in `render': bad value for range (ArgumentError)
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/block.rb:151:in `render_token'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/profiler/hooks.rb:5:in `block in render_token_with_profiling'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/profiler.rb:80:in `profile_token_render'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/profiler/hooks.rb:4:in `render_token_with_profiling'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/block.rb:135:in `block in render_all'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/block.rb:122:in `each'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/block.rb:122:in `render_all'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/block.rb:108:in `render'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/tags/highlight.rb:32:in `render'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/block.rb:151:in `render_token'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/profiler/hooks.rb:5:in `block in render_token_with_profiling'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/profiler.rb:80:in `profile_token_render'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/profiler/hooks.rb:4:in `render_token_with_profiling'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/block.rb:135:in `block in render_all'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/block.rb:122:in `each'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/block.rb:122:in `render_all'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/block.rb:108:in `render'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/template.rb:210:in `block in render'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/template.rb:262:in `with_profiling'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/template.rb:209:in `render'
	from /Library/Ruby/Gems/2.0.0/gems/liquid-3.0.6/lib/liquid/template.rb:222:in `render!'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/liquid_renderer/file.rb:28:in `block (2 levels) in render!'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/liquid_renderer/file.rb:40:in `measure_bytes'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/liquid_renderer/file.rb:27:in `block in render!'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/liquid_renderer/file.rb:47:in `measure_time'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/liquid_renderer/file.rb:26:in `render!'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/renderer.rb:134:in `render_liquid'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/renderer.rb:82:in `run'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/site.rb:452:in `block (2 levels) in render_docs'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/site.rb:450:in `each'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/site.rb:450:in `block in render_docs'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/site.rb:449:in `each'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/site.rb:449:in `render_docs'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/site.rb:190:in `render'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/site.rb:69:in `process'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/command.rb:26:in `process_site'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/commands/build.rb:63:in `build'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/commands/build.rb:34:in `process'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/lib/jekyll/commands/serve.rb:37:in `block (2 levels) in init_with_program'
	from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `call'
	from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
	from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
	from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
	from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
	from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
	from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.0/exe/jekyll:13:in `<top (required)>'
	from /usr/local/bin/jekyll:23:in `load'
	from /usr/local/bin/jekyll:23:in `<main>'

The same project works on Jekyll 2.4.0.

not working, Liquid syntax error

this plugin is freaking amazing cause I can update my page automatically when I update my project readme. saving a lot of time to not update things in 2 different places.

anyways I get an error:
Liquid Exception: Liquid syntax error (line 1): Unknown tag 'github_sample' in projects/king-bot/index.md

I installed the gem, and added it to the plugins (btw. change that in your documentation please :) )

tried to bundle exec Jekyll serve but no luck at all

implemented like:
{% github_sample scriptworld-git/king-bot/blob/master/README.md 5 %}

also tried:
{%- github_sample scriptworld-git/king-bot/blob/master/README.md 5 -%}

and even full path:
{% github_sample https://github.com/scriptworld-git/king-bot/blob/master/README.md 5 %}

Plugin cannot be installed in Jekyll 4

Due to the Jekyll dependency in the gemspec set to ~> 3.0, Jekyll 4 refuses to load this plugin.
I created PR #14 to resolve the dependency and was able to successfully test it in my deployment.

First line indentation

I get the first line indented

    ### ============ 2. Download =========
### File location defaults to '~/GDCData'
GDCdownload(query = query,
            method = "client")

with the line numbers

  {% highlight r %}
    {% github_sample jvwong/docker_enrichment_workflow_gdc/blob/01442e4397c036c65da74563aa633f45d9a8117d/src/scripts/get_data.R 29 32 %}
  {% endhighlight %}

Possible to pass repo as a variable instead of as a string?

I'm in a bit of a pickle; I really want to do something like this:

{% assign readmepath=page.github_repo | append: "/master/README.md" %}
{% capture readme_in_markdown %}{% github_sample readmepath %}{% endcapture %}
{{ readme_in_markdown | markdownify }}

But...github_sample thinks that readmepath is the path I'm talking about. Is there anyway to upgrade this gem so that it handles a variable name or a url string?

People have asked about this stuff before in places like this

I'm trying to store github repos in my frontmatter and then, if extant and valid, fetch the README.md files.

Thanks!

Appears to have broken Jekyll

I modified my Gemfile and did a bundle, but now I'm getting the following error whenever I try to jekyll serve:

/Library/Ruby/Gems/2.0.0/gems/bundler-1.14.5/lib/bundler/rubygems_ext.rb:45:in `full_gem_path': uninitialized constant Bundler::Plugin::API::Source (NameError)
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:1391:in `contains_requirable_file?'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:68:in `block in require'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:823:in `block in each'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:822:in `each'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:822:in `each'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:67:in `find'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:67:in `require'
        from /Library/Ruby/Gems/2.0.0/gems/bundler-1.14.5/lib/bundler/plugin/api/source.rb:2:in `<top (required)>'
        from /Library/Ruby/Gems/2.0.0/gems/bundler-1.14.5/lib/bundler/rubygems_ext.rb:45:in `full_gem_path'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:1391:in `contains_requirable_file?'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:68:in `block in require'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:823:in `block in each'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:822:in `each'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:822:in `each'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:67:in `find'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:67:in `require'
        from /Library/Ruby/Gems/2.0.0/gems/bundler-1.14.5/lib/bundler.rb:12:in `<top (required)>'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `require'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
        from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.1/lib/jekyll/plugin_manager.rb:34:in `require_from_bundler'
        from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.4.1/exe/jekyll:9:in `<top (required)>'
        from /usr/local/bin/jekyll:23:in `load'
        from /usr/local/bin/jekyll:23:in `<main>'

Any ideas?

Possible to cache repo code ?

When I add to many github_sample tag in my markdown files.
It jekyll frequently reported Error: execution expired.

GitHub URI retrieval uses Kernel#open which is deprecated

Discovered in testing today that the plugin is using Kernel#open instead of
URI#open when retrieving contents from GitHub. Ruby threw the following
deprecation notice:

Jekyll Feed: Generating feed for posts
/home/akale/repository/code/codecommit/kriation/blog/vendor/ruby/2.7.0/gems/jekyll_github_sample-0.3.2/lib/jekyll_github_sample/code_tag.rb:19:
warning: calling URI.open via Kernel#open is deprecated, call URI.open directly
or use URI#open

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.