quivjek 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/quivjek/version.rb +3 -0
- data/lib/quivjek.rb +147 -0
- data/quivjek.gemspec +26 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d65ca409aa9ca6a4c89f989eec03ccd3e66a1e9c
|
4
|
+
data.tar.gz: 469b356a3621fa41b28bd33cb7ed135288b12c0e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc8ab9c141826190767d34878e239e91eb1d6fb66e3ac55f2ce85853918e100408c5096fc3939075e74794fb90c27963acc67dc0b4924f34a67c2c92fc9c03e9
|
7
|
+
data.tar.gz: f386bf52dd19ef84284c5d6be28733757d48b0be4238413c34156e81a79e2833f6a21c480ac5131c8794862d0c3d69db58e3e3cc15a43798a80667afcadf24a8
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ben Bjurstrom
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#Quivjek: A Jekyll plugin for seamless publication of Quiver notebooks
|
2
|
+
[![Build Status](https://travis-ci.org/benbjurstrom/quivjek.svg?branch=master)](https://travis-ci.org/benbjurstrom/quivjek)
|
3
|
+
|
4
|
+
Quivjek is a Jekyll plugin that automatically copies a specified Quiver notebook to your Jekyll _posts folder whenever the jekyll build command runs. Quivjek also copies and properly links any images contained in a Quiver note to your Jekyll images folder.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
1. Install the quivjek gem
|
8
|
+
```
|
9
|
+
gem install quivjek
|
10
|
+
```
|
11
|
+
2. In jekyll's \_config.yml file add quivjek to the gems array
|
12
|
+
```
|
13
|
+
gems: [quivjek]
|
14
|
+
```
|
15
|
+
3. Point quivjek to the Quiver notebook of choice by adding the `notebook_dir:` key in jekyll's \_config.yml file and set the value equal to the path to your chosen Quiver notebook. For example:
|
16
|
+
```
|
17
|
+
#jekyll _config.yml
|
18
|
+
notebook_dir:~/Dropbox/Quiver/Quiver.qvlibrary/14F2BCE0-1B08-4ED6-993A-17C8AB0316E2.qvnotebook
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
Simply run ```jekyll build``` and quivjek will automatically add your Quiver notes to your jekyll site.
|
23
|
+
|
24
|
+
## How to I find my quiver notebook?
|
25
|
+
Your Quiver notebook is contained within your Quiver library. Your Quiver library is a folder that ends with the extension .qvlibrary. You can find the location of your Quiver library in Quiver's menu by going under Quiver -> Preferences -> Sync and checking the Library Location. If using the command line you can cd into it like normal. If using finder, right click on the .qvlibrary and click show package contents.
|
26
|
+
|
27
|
+
Now that you're inside your Quiver libary folder you should see all of that libary's notebooks. Quiver notebooks are folders that end with the .qvnotebook extension. They will be named with a UUID as indiacted above. To determine the Quiver notebook's name check the meta.json file contained within each .qvnotebook folder.
|
28
|
+
|
29
|
+
## Other info
|
30
|
+
All quiver notes must be entirely composed of markdown or code cells.
|
31
|
+
|
32
|
+
Quivjek will ignore any posts tagged as `draft`
|
33
|
+
|
34
|
+
Quivjek sets the post created date based on the Quiver created date. Currently there's no easy way to modify the Quiver create date short of modifying the timestamp in the note's meta.json file. Eventually I'd like to allow overriding this value through custom fronmatter.
|
35
|
+
|
36
|
+
Quivjek currently copies all notes and images to the subfolders `/_posts/quiver` and `/images/q` respectivly. On build quivjek deletes all files from these subfolders and re-copies the notes and images from the Quiver notebook. This is done to clean up any deleted or renamed items. Eventually I'd like to save a manafest and only update the notes and images that have changed or been removed since the last build.
|
37
|
+
|
38
|
+
## Development
|
39
|
+
|
40
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
41
|
+
|
42
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/benbjurstrom/quivjek. This is my first time using ruby so pull requests to improve code style are welcome. Thanks to Bradley Curran's [quiver2jekyll](https://github.com/bradley-curran/quiver2jekyll/) package for pointing me in the right direction.
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "quivjek"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/quivjek.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require "date"
|
3
|
+
require "json"
|
4
|
+
require "fileutils"
|
5
|
+
require "quivjek/version"
|
6
|
+
require "jekyll"
|
7
|
+
|
8
|
+
Jekyll::Hooks.register :site, :after_init do |site|
|
9
|
+
q = Quivjek.new(site)
|
10
|
+
q.load_posts_from_quiver
|
11
|
+
end
|
12
|
+
|
13
|
+
class Quivjek
|
14
|
+
|
15
|
+
def initialize( site )
|
16
|
+
self.showhelp('The qivjek plugin requires notebook_dir be set in your _config.yml file') unless site.config.key?('notebook_dir')
|
17
|
+
|
18
|
+
@site = site
|
19
|
+
@jekyll_dir = site.source
|
20
|
+
@notebook_dir = site.config['notebook_dir']
|
21
|
+
@post_dir = File.join(@jekyll_dir, "/_posts/quiver")
|
22
|
+
@img_dir = File.join(@jekyll_dir, "/images/q")
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_posts_from_quiver()
|
27
|
+
|
28
|
+
Dir.mkdir(@post_dir) unless File.exists?(@post_dir)
|
29
|
+
Dir.mkdir(@img_dir) unless File.exists?(@img_dir)
|
30
|
+
|
31
|
+
# Clear out the _posts/quiver and images/q directories in case any posts or images have been renamed
|
32
|
+
FileUtils.rm_rf Dir.glob(@post_dir + '/*')
|
33
|
+
FileUtils.rm_rf Dir.glob(@img_dir + '/*')
|
34
|
+
|
35
|
+
# Pass the path of each .qvnote to the copy_post method
|
36
|
+
Dir.foreach(@notebook_dir) do |item|
|
37
|
+
next if item == '.' or item == '..' or item == 'meta.json' or item == '.keep'
|
38
|
+
self.copy_note(File.join(@notebook_dir, item))
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def showhelp(message)
|
46
|
+
puts message.red + "\n"
|
47
|
+
exit
|
48
|
+
end
|
49
|
+
|
50
|
+
def copy_note(note_dir)
|
51
|
+
metapath = File.join(note_dir, "meta.json")
|
52
|
+
contentpath = File.join(note_dir, "content.json")
|
53
|
+
imagepath = File.join(note_dir, "resources")
|
54
|
+
|
55
|
+
showhelp("meta.json doesn't exist") unless File.exist? metapath
|
56
|
+
metajson = JSON.parse(File.read(metapath))
|
57
|
+
|
58
|
+
# Skip this note if tagged with draft
|
59
|
+
metajson["tags"].each do |tag|
|
60
|
+
return if tag == 'draft'
|
61
|
+
end
|
62
|
+
|
63
|
+
showhelp(contentpath + "content.json doesn't exist") unless File.exist? contentpath
|
64
|
+
|
65
|
+
self.copy_note_images(imagepath) if File.exist?(imagepath)
|
66
|
+
|
67
|
+
filename = self.get_filename(metajson)
|
68
|
+
output = self.add_frontmatter(metajson)
|
69
|
+
|
70
|
+
contentjson = JSON.parse(File.read(contentpath))
|
71
|
+
output = self.add_content(contentjson, output)
|
72
|
+
|
73
|
+
File.open(File.join(@post_dir, filename), "w") { |file| file.write(output) }
|
74
|
+
end
|
75
|
+
|
76
|
+
def copy_note_images(imagepath)
|
77
|
+
|
78
|
+
# copy all images from the note's resources dir to the jekyll images/q dir
|
79
|
+
Dir.foreach(imagepath) do |item|
|
80
|
+
next if item == '.' or item == '..'
|
81
|
+
FileUtils.cp(File.join(imagepath, item), @img_dir)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
def get_filename(metajson)
|
87
|
+
title = metajson["title"].gsub(" ", "-").downcase
|
88
|
+
|
89
|
+
created_at_date = DateTime.strptime(metajson["created_at"].to_s, "%s")
|
90
|
+
day = "%02d" % created_at_date.day
|
91
|
+
month = "%02d" % created_at_date.month
|
92
|
+
year = created_at_date.year
|
93
|
+
|
94
|
+
return "#{year}-#{month}-#{day}-#{title}.md"
|
95
|
+
end
|
96
|
+
|
97
|
+
def add_frontmatter(metajson)
|
98
|
+
tags = metajson["tags"].map { |tag| " - #{tag}" }.join("\n")
|
99
|
+
output = <<eos
|
100
|
+
---
|
101
|
+
layout: post
|
102
|
+
title: "#{metajson["title"]}"
|
103
|
+
eos
|
104
|
+
|
105
|
+
if !tags.empty?
|
106
|
+
output << "tags:\n#{tags}\n"
|
107
|
+
end
|
108
|
+
|
109
|
+
output << "---\n\n"
|
110
|
+
|
111
|
+
return output
|
112
|
+
end
|
113
|
+
|
114
|
+
def add_content(contentjson, output)
|
115
|
+
contentjson["cells"].each do |cell|
|
116
|
+
case cell["type"]
|
117
|
+
when "code"
|
118
|
+
output << "{% highlight #{cell["language"]} %}\n"
|
119
|
+
output << "#{cell["data"]}\n"
|
120
|
+
output << "{% endhighlight %}\n"
|
121
|
+
when "markdown"
|
122
|
+
|
123
|
+
c = cell["data"]
|
124
|
+
|
125
|
+
# Scan the markdown cell for images
|
126
|
+
images = c.scan(/!\[(.*)\]\(quiver-image-url\/(.*)\)/)
|
127
|
+
images.each do |image|
|
128
|
+
|
129
|
+
# Modify the image source to point to the alt tag in the images/q/ folder
|
130
|
+
c = c.gsub(image[1], image[0])
|
131
|
+
|
132
|
+
# Rename the image (since the image has already been copied from the qvnote folder)
|
133
|
+
File.rename(File.join(@img_dir, image[1]), File.join(@img_dir, image[0]))
|
134
|
+
end
|
135
|
+
|
136
|
+
output << "#{c.gsub("quiver-image-url", "/images/q")}\n"
|
137
|
+
else
|
138
|
+
showhelp(frontmatter_title + " :all cells must be code or markdown types")
|
139
|
+
end
|
140
|
+
|
141
|
+
output << "\n"
|
142
|
+
|
143
|
+
return output
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
data/quivjek.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'quivjek/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "quivjek"
|
8
|
+
spec.version = Quivjek::VERSION
|
9
|
+
spec.authors = ["Ben Bjurstrom"]
|
10
|
+
spec.email = ["ben@jelled.fake"]
|
11
|
+
|
12
|
+
spec.summary = "A Jekyll plugin for seamless publication of Quiver notebooks"
|
13
|
+
spec.description = "A Jekyll plugin that automatically copies a Quiver notebook to your Jekyll _posts folder whenever the jekyll build command runs. Quivjek also copies and properly links any images contained in a Quiver note to your Jekyll images folder."
|
14
|
+
spec.homepage = "https://github.com/benbjurstrom/keyburner"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
25
|
+
spec.add_development_dependency "jekyll", ">= 2.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quivjek
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Bjurstrom
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jekyll
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
description: A Jekyll plugin that automatically copies a Quiver notebook to your Jekyll
|
70
|
+
_posts folder whenever the jekyll build command runs. Quivjek also copies and properly
|
71
|
+
links any images contained in a Quiver note to your Jekyll images folder.
|
72
|
+
email:
|
73
|
+
- ben@jelled.fake
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- .travis.yml
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/quivjek.rb
|
87
|
+
- lib/quivjek/version.rb
|
88
|
+
- quivjek.gemspec
|
89
|
+
homepage: https://github.com/benbjurstrom/keyburner
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.0.14
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: A Jekyll plugin for seamless publication of Quiver notebooks
|
113
|
+
test_files: []
|