quivjek 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89f2083f8fa0d38194df93c7d644cfedbe29cb6e
4
- data.tar.gz: 3d986b97b490e32f475c79843ca871b065b202be
3
+ metadata.gz: cddb138a8ddddbc65215afc6014cd62855558b8a
4
+ data.tar.gz: e0e2064128abfdcfd12316f257b44c2cbe7957ee
5
5
  SHA512:
6
- metadata.gz: e2ee61b8194aa8f511eed12d8df343287efa1cd9f93ba67838923c4e55b3c1ce227b7d16b9206d3e909687ed9208371e6c859b0bee49bf091f3e74c9c8388351
7
- data.tar.gz: 596e4f64b2b3ef9a121732fa76af0b68e183ddaeae1993ea24d4a47d985228c5bc6509ad9770dd92857e9d8c060b6d723ffc71f44aec34f4c6c21188ccdd1929
6
+ metadata.gz: 12f0fe9e24a397a5d7e47e36b03a787780099b5c1de9e1c9c5b765e6b7eb643cf96459eee85b0eee2cd5cc6e1b81d58438e127f58ebfba12ad374970115010e7
7
+ data.tar.gz: e1c94c28e1eda6225d15aefad543a777291758ee0c1042acd98479a1f4ada284c38b4c0924200929eb6d8617cf4b5d7ffd028cb2fb8f4a1256873430476991a5
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .DS_Store
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /Gemfile.lock
@@ -9,4 +10,5 @@
9
10
  /tmp/
10
11
  /.idea
11
12
  /test/resources/_posts/quiver
12
- /test/resources/images/q
13
+ /test/resources/images/q
14
+ /vendor/
data/README.md CHANGED
@@ -1,39 +1,55 @@
1
1
  # Quivjek: A Jekyll plugin for seamless publication of Quiver notebooks
2
2
  [![Build Status](https://travis-ci.org/benbjurstrom/quivjek.svg?branch=master)](https://travis-ci.org/benbjurstrom/quivjek)
3
3
 
4
- Quivjek is a Jekyll plugin that automatically exports all notes from a specified Quiver notebook to your _posts folder when the jekyll build command is run. Quivjek also copies and properly links any images contained in a Quiver note to your Jekyll images folder.
4
+ Quivjek is a [Jekyll](https://jekyllrb.com/) plugin that automatically exports all notes from a specified [Quiver](http://happenapps.com/#quiver) notebook to your _posts folder when the jekyll build command is run. Quivjek also copies and properly links any images contained in a Quiver note to your Jekyll images folder.
5
5
 
6
6
  ## Installation
7
7
  1. Install the quivjek gem
8
- ```
9
- gem install quivjek
10
- ```
8
+ ```bash
9
+ gem install quivjek
10
+ ```
11
11
  2. Add quivjek to the gems array found in the _config.yml file.
12
- ```
13
- #jekyll_dir/_config.yml
14
- gems: [quivjek]
15
- ```
12
+ ```yaml
13
+ #jekyll_dir/_config.yml
14
+ gems: [quivjek]
15
+ ```
16
16
  3. Point quivjek to the Quiver notebook of choice by adding the `notebook_dir:` key to the \_config.yml file with a value equal to your notebooks file path. For example:
17
- ```
18
- #jekyll_dir/_config.yml
19
- notebook_dir:~/Dropbox/Quiver/Quiver.qvlibrary/14F2BCE0-1B08-4ED6-993A-17C8AB0316E2.qvnotebook
20
- ```
17
+ ```yaml
18
+ #jekyll_dir/_config.yml
19
+ notebook_dir:~/Dropbox/Quiver/Quiver.qvlibrary/14F2BCE0-1B08-4ED6-993A-17C8AB0316E2.qvnotebook
20
+ ```
21
21
 
22
- To determine a notebook's filepath right click on the note in the Quiver sidebar and choose open in finder. Be aware that Quiver notebooks are folders ending in the .qvnotebook extension and named with a random UUID as in the example above.
22
+ To determine a Quiver notebook's filepath right click on the note in the Quiver sidebar and choose open in finder. Be aware that Quiver notebooks are folders ending in the .qvnotebook extension and named with a random UUID as in the example above.
23
23
 
24
24
  ## Usage
25
- Simply run `jekyll build` and quivjek will automatically add your Quiver notes to your jekyll site
25
+ Run `jekyll build` and quivjek will automatically copy your Quiver notes to your jekyll _posts folder prior to build.
26
26
 
27
27
  ## Things you should know
28
- All quiver notes must be entirely composed of markdown or code cells.
28
+ 1. All quiver notes must be entirely composed of markdown or code cells.
29
29
 
30
- Quivjek will ignore any posts tagged as `draft`
30
+ 1. Quivjek will ignore any posts tagged as `draft`
31
31
 
32
- Quivjek sets the post created date based on the note's created date. Currently there's no easy way to modify the note's create date in Quiver short of modifying the timestamp in the note's meta.json file. Eventually I'd like to allow overriding this value through custom frontmatter.
32
+ 1. Optionally you can include a YAML front matter envelope to your Quiver note.
33
33
 
34
- Quivjek currently copies all notes and images to the jekyll directory within 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 been modified or deleted since the last build.
34
+ ```yaml
35
+
36
+ ---
37
+ title: This is an example post
38
+ date: '2016-09-14'
39
+ ---
40
+
41
+ Some content...
42
+ ```
35
43
 
36
- When an image is added to a markdown cell, Quiver renames the file and sets the original file name as the image tag's alt attribute. For example the image `big-claw-puppy-on-wood-floor.jpg` becomes `![big-claw-puppy-on-wood-floor.jpg](quiver-image-url/642370E09A291BC1601CFD68B44A5C16.jpg)`. For SEO purposes quivjek reverses this process by renaming the image to whatever is found in your alt tag. Therefore it is recormended your alt tags are lowercase, slug-ified, unique, and end in the image file extension.
44
+ * By default Quivjek sets the front matter date (and markdown file name) based on the Quiver note's created date metadata. This can be overridden by adding the date front matter to your Quiver note.
45
+
46
+ * By default Quivjek sets the front matter title (and markdown file name) equal to the Quiver note's title. This can be overridden by adding the title front matter to your quiver note.
47
+
48
+ * By default Quivjek adds the Quiver note's tags as front matter tags.
49
+
50
+ 1. Quivjek currently copies all notes and images to the jekyll directory within the subfolders `/_posts/quiver` and `/images/q` respectively. 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 manifest and only update the notes and images that have been modified or deleted since the last build.
51
+
52
+ 1. When an image is added to a markdown cell, Quiver renames the file and sets the original file name as the image tag's alt attribute. For example the image `big-claw-puppy-on-wood-floor.jpg` becomes `![big-claw-puppy-on-wood-floor.jpg](quiver-image-url/642370E09A291BC1601CFD68B44A5C16.jpg)`. For SEO purposes quivjek reverses this process by renaming the image to whatever is found in your alt tag. Therefore it is recommended your alt tags are lowercase, slug-ified, unique, and end in the image file extension.
37
53
 
38
54
  ## Development
39
55
  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.
@@ -4,6 +4,8 @@ require "json"
4
4
  require "fileutils"
5
5
  require "quivjek/version"
6
6
  require "jekyll"
7
+ require "front_matter_parser"
8
+ require "yaml"
7
9
 
8
10
  Jekyll::Hooks.register :site, :after_init do |site|
9
11
  q = Quivjek.new(site)
@@ -48,29 +50,51 @@ class Quivjek
48
50
  end
49
51
 
50
52
  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))
53
+ # Load the quiver note meta.json file.
54
+ metajson = load_meta_json(note_dir)
57
55
 
58
56
  # Skip this note if tagged with draft
59
57
  metajson["tags"].each do |tag|
60
58
  return if tag == 'draft'
61
59
  end
62
60
 
63
- showhelp(contentpath + "content.json doesn't exist") unless File.exist? contentpath
64
-
61
+ # Copy the notes images to the jekyll directory
62
+ imagepath = File.join(note_dir, "resources")
65
63
  self.copy_note_images(imagepath) if File.exist?(imagepath)
66
64
 
67
- filename = self.get_filename(metajson)
68
- output = self.add_frontmatter(metajson)
65
+ # Load the quiver note content.json file and merge its cells.
66
+ contentjson = load_content_json(note_dir)
67
+ content = self.merge_cells(contentjson, '')
69
68
 
70
- contentjson = JSON.parse(File.read(contentpath))
71
- output = self.add_content(contentjson, output)
69
+ # Parse out optional frontmatter from the content
70
+ parsed = FrontMatterParser.parse(content)
71
+ fm = parsed.front_matter
72
+ content = parsed.content
72
73
 
74
+ # Set some default frontmatter and combine with content
75
+ fm = set_default_frontmatter(fm, metajson)
76
+ output = fm.to_yaml + "---\n" + content
77
+
78
+ # Write the markdown file to the jekyll dir
79
+ filename = self.get_filename(fm)
73
80
  File.open(File.join(@post_dir, filename), "w") { |file| file.write(output) }
81
+
82
+ end
83
+
84
+ def load_meta_json(dir)
85
+ metapath = File.join(dir, "meta.json")
86
+ showhelp("meta.json doesn't exist") unless File.exist? metapath
87
+ metajson = JSON.parse(File.read(metapath))
88
+
89
+ return metajson
90
+ end
91
+
92
+ def load_content_json(dir)
93
+ contentpath = File.join(dir, "content.json")
94
+ showhelp(contentpath + "content.json doesn't exist") unless File.exist? contentpath
95
+ contentjson = JSON.parse(File.read(contentpath))
96
+
97
+ return contentjson
74
98
  end
75
99
 
76
100
  def copy_note_images(imagepath)
@@ -83,35 +107,37 @@ class Quivjek
83
107
 
84
108
  end
85
109
 
86
- def get_filename(metajson)
87
- title = metajson["title"].gsub(" ", "-").downcase
110
+ def get_filename(fm)
111
+ title = fm["title"].gsub(" ", "-").downcase
112
+ date = DateTime.parse(fm["date"])
88
113
 
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
114
+ day = "%02d" % date.day
115
+ month = "%02d" % date.month
116
+ year = date.year
93
117
 
94
118
  return "#{year}-#{month}-#{day}-#{title}.md"
95
119
  end
96
120
 
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
121
+ def set_default_frontmatter(fm, metajson)
122
+
123
+ # If certain frontmatter is missing default to quiver metadata
124
+ fm['title'] = metajson['title'] unless fm['title']
104
125
 
126
+ if !fm.key?("date")
127
+ date = DateTime.strptime(metajson["created_at"].to_s, "%s")
128
+ fm['date'] = date.strftime('%Y-%m-%d')
129
+ end
130
+
131
+ tags = metajson["tags"].map { |tag| " - #{tag}" }.join("\n")
105
132
  if !tags.empty?
106
- output << "tags:\n#{tags}\n"
133
+ fm['tags'] = tags
107
134
  end
108
135
 
109
- output << "---\n\n"
136
+ return fm
110
137
 
111
- return output
112
138
  end
113
139
 
114
- def add_content(contentjson, output)
140
+ def merge_cells(contentjson, output)
115
141
  contentjson["cells"].each do |cell|
116
142
  case cell["type"]
117
143
  when "code"
@@ -1,3 +1,3 @@
1
1
  class Quivjek
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.add_runtime_dependency "front_matter_parser", "0.0.4"
23
+
22
24
  spec.add_development_dependency "bundler", "~> 1.12"
23
25
  spec.add_development_dependency "rake", "~> 10.0"
24
26
  spec.add_development_dependency "minitest", "~> 5.0"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quivjek
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Bjurstrom
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-15 00:00:00.000000000 Z
11
+ date: 2017-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: front_matter_parser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.4
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -106,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
120
  version: '0'
107
121
  requirements: []
108
122
  rubyforge_project:
109
- rubygems_version: 2.0.14
123
+ rubygems_version: 2.6.10
110
124
  signing_key:
111
125
  specification_version: 4
112
126
  summary: A Jekyll plugin for seamless publication of Quiver notebooks