bergamasco 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/bergamasco/markdown.rb +4 -20
- data/lib/bergamasco/version.rb +1 -1
- data/spec/markdown_spec.rb +3 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d0569cf27c3e1b39f7f627e8e444904c4d559ac
|
4
|
+
data.tar.gz: b35abe4ff49c530007e5b67648d0d5fba612334f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca6e9010494aa2cd9a0e1fbf8a0ea371a40fc074ea5ec5616e079211baa171961cc02ee1f52594b6957f18f9a74a3de50dd0ec9035d801a0ed16fb7061eea825
|
7
|
+
data.tar.gz: 7ac8ff15b82f376686abd7c50a6c604165542a511b3613eb1e2ead5321597f83f92e827ebae5c8d1452c4e7ab492fdc5d73077f5dfbd0a2629dfdff6658acb8d
|
data/Gemfile.lock
CHANGED
data/lib/bergamasco/markdown.rb
CHANGED
@@ -37,7 +37,7 @@ module Bergamasco
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def self.read_yaml_for_doi_metadata(filepath, options={})
|
40
|
-
keys = options[:keys] || ["title", "author", "date", "tags"]
|
40
|
+
keys = options[:keys] || ["title", "author", "date", "tags", "summary", "doi", "type", "version", "citation"]
|
41
41
|
unless File.exist?(filepath)
|
42
42
|
parentdir = Pathname.new(filepath).parent
|
43
43
|
FileUtils.mkdir_p parentdir
|
@@ -51,7 +51,7 @@ module Bergamasco
|
|
51
51
|
content = YAML_FRONT_MATTER_REGEXP.match(file).post_match
|
52
52
|
html = render_html(content, options)
|
53
53
|
metadata["summary"] = Bergamasco::Summarize.summary_from_html(html, options)
|
54
|
-
metadata["
|
54
|
+
metadata["citation"] = extract_references(html)
|
55
55
|
metadata["date"] = metadata["date"].iso8601
|
56
56
|
metadata
|
57
57
|
end
|
@@ -70,25 +70,9 @@ module Bergamasco
|
|
70
70
|
end
|
71
71
|
|
72
72
|
# expects a references list generated by pandoc
|
73
|
-
def self.extract_references(html
|
73
|
+
def self.extract_references(html)
|
74
74
|
doc = Nokogiri::HTML(html)
|
75
|
-
doc.xpath('//div[@id="refs"]/div/@id').map
|
76
|
-
id = ref.value[4..-1]
|
77
|
-
|
78
|
-
if /(http|https):\/\/(dx\.)?doi\.org\/(\w+)/.match(id)
|
79
|
-
uri = Addressable::URI.parse(id)
|
80
|
-
id = uri.path[1..-1].upcase
|
81
|
-
type = "DOI"
|
82
|
-
else
|
83
|
-
type = "URL"
|
84
|
-
end
|
85
|
-
|
86
|
-
{
|
87
|
-
value: id,
|
88
|
-
related_identifier_type: type,
|
89
|
-
relation_type: "References"
|
90
|
-
}
|
91
|
-
end
|
75
|
+
doc.xpath('//div[@id="refs"]/div/@id').map { |ref| ref.value[4..-1] }
|
92
76
|
end
|
93
77
|
end
|
94
78
|
end
|
data/lib/bergamasco/version.rb
CHANGED
data/spec/markdown_spec.rb
CHANGED
@@ -53,12 +53,7 @@ describe Bergamasco::Markdown do
|
|
53
53
|
filepath = fixture_path + 'cool-dois.html.md'
|
54
54
|
separator = "READMORE"
|
55
55
|
metadata = subject.read_yaml_for_doi_metadata(filepath, separator: separator, csl: 'spec/apa.csl', bibliography: 'spec/references.bib')
|
56
|
-
expect(metadata["
|
57
|
-
:related_identifier_type=>"URL",
|
58
|
-
:relation_type=>"References"},
|
59
|
-
{ :value=>"10.1371/JOURNAL.PONE.0115253",
|
60
|
-
:related_identifier_type=>"DOI",
|
61
|
-
:relation_type=>"References" }])
|
56
|
+
expect(metadata["citation"]).to eq(["https://www.w3.org/Provider/Style/URI", "https://doi.org/10.1371/journal.pone.0115253"])
|
62
57
|
end
|
63
58
|
|
64
59
|
it 'should write yaml' do
|
@@ -88,12 +83,7 @@ describe Bergamasco::Markdown do
|
|
88
83
|
filepath = fixture_path + 'cool-dois.html.md'
|
89
84
|
file = IO.read(filepath)
|
90
85
|
html = subject.render_html(file, skip_yaml_header: true, csl: 'spec/apa.csl', bibliography: 'spec/references.bib')
|
91
|
-
refs = subject.extract_references(html
|
92
|
-
expect(refs).to eq([
|
93
|
-
:related_identifier_type=>"URL",
|
94
|
-
:relation_type=>"References"},
|
95
|
-
{ :value=>"10.1371/JOURNAL.PONE.0115253",
|
96
|
-
:related_identifier_type=>"DOI",
|
97
|
-
:relation_type=>"References" }])
|
86
|
+
refs = subject.extract_references(html)
|
87
|
+
expect(refs).to eq(["https://www.w3.org/Provider/Style/URI", "https://doi.org/10.1371/journal.pone.0115253"])
|
98
88
|
end
|
99
89
|
end
|