jekyll-scholar 5.15.0 → 5.16.0

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
  SHA256:
3
- metadata.gz: e0a2e628b1d24021608d99ed8d5dda0e76999df53944a9de3f73f241e7184d84
4
- data.tar.gz: 3a3289d5444bc07f819ea2705d96f8ad53ea2f62abceb1ba2d60dc4b97d1b5af
3
+ metadata.gz: 8d41dda4e23371eb67f351f9e305c6ee39792396207a9b9a9bed2b942e166e9d
4
+ data.tar.gz: 58d5fb482ac8db32b6329804b70003d62108d96f095111fcab64cd7731656beb
5
5
  SHA512:
6
- metadata.gz: 8d2be39fb58d5bb70a10ffa6736bf155f4b8c84193bd8030abe8ac1ee1327eac4603510d62a33370061b928b7c8934ac2786ea2db45d2d52a87998dd8bae5f13
7
- data.tar.gz: 76f1963d4fc2af3c5158aff23633db793c21426cab82ba7a939d5af7288624f87c216cc73d5b4c1eedc9cc4e2b0438d5f3b45cef24b425907f62e045437fcde1
6
+ metadata.gz: 63981abf3ed1e2ed91bd698a6fb7ea63dae32a9a4821b3e5d5ca6cf5d0decad2427522c35ecfe2287b54984deee77cea2deedf153e6a753ea4b6da4babdbb515
7
+ data.tar.gz: 21fde19cc38570542d21a73f5bfa2ff08dda5ac871cea4480dd355bb1407949d07523776d09cc77cf2626b639f2cee71df496f5e479a714fc31081d1ad240eb8
@@ -334,6 +334,59 @@ Feature: Details
334
334
  And I should see "<a[^>]+href=\"/bibliography/ruby/\">" in "_site/scholar/index.html"
335
335
  And the "_site/bibliography/ruby/index.html" file should exist
336
336
 
337
+ @tags @details
338
+ Scenario: Detail page URLs can have custom permalinks
339
+ Given I have a configuration file with "permalink" set to "/:title/"
340
+ And I have a scholar configuration with:
341
+ | key | value |
342
+ | source | ./_bibliography |
343
+ | bibliography | references |
344
+ | details_layout | details.html |
345
+ | details_permalink | /:details_dir/:year/:doi:extension |
346
+ And I have a "_bibliography" directory
347
+ And I have a file "_bibliography/references.bib":
348
+ """
349
+ @book{rubydoi,
350
+ title = {The Ruby Programming Language},
351
+ author = {Flanagan, David and Matsumoto, Yukihiro},
352
+ year = {2008},
353
+ publisher = {O'Reilly Media},
354
+ doi = {10.0000/1111}
355
+ }
356
+
357
+ @book{ruby,
358
+ title = {The Ruby Programming Language},
359
+ author = {Flanagan, David and Matsumoto, Yukihiro},
360
+ year = {2008},
361
+ publisher = {O'Reilly Media}
362
+ }
363
+ """
364
+ And I have a "_layouts" directory
365
+ And I have a file "_layouts/details.html":
366
+ """
367
+ ---
368
+ ---
369
+ <html>
370
+ <head></head>
371
+ <body>
372
+ {{ page.entry.title }}
373
+ </body>
374
+ </html>
375
+ """
376
+ And I have a page "scholar.html":
377
+ """
378
+ ---
379
+ ---
380
+ {% bibliography %}
381
+ """
382
+ When I run jekyll
383
+ Then the _site directory should exist
384
+ And the "_site/scholar/index.html" file should exist
385
+ And I should see "<a[^>]+href=\"/bibliography/2008/10.0000/1111/\">" in "_site/scholar/index.html"
386
+ And I should see "<a[^>]+href=\"/bibliography/2008/ruby/\">" in "_site/scholar/index.html"
387
+ And the "_site/bibliography/2008/10.0000/1111/index.html" file should exist
388
+ And the "_site/bibliography/2008/ruby/index.html" file should exist
389
+
337
390
  @generators @parse_months
338
391
  Scenario: Months are parsed by default
339
392
  Given I have a scholar configuration with:
@@ -46,6 +46,22 @@ module Jekyll
46
46
  'details_dir' => 'bibliography',
47
47
  'details_layout' => 'bibtex.html',
48
48
  'details_link' => 'Details',
49
+
50
+ # 'details_permalink': URL template for generating the filenames of the details pages.
51
+ #
52
+ # Example: if we had a citation key 'ruby':
53
+ # '/:details_dir/:year/:key:extension' would produce:
54
+ # '/bibliography/2008/ruby.html' if global permalinks end in .html
55
+ # '/bibliography/2008/ruby/index.html' if global permalinks end in "/" or are set to "pretty"
56
+ #
57
+ # Valid template parameters:
58
+ # ":details_dir" The value of the details_dir field in the scholar config
59
+ # ":key" The bibtex citation key.
60
+ # ":doi" The DOI. If the DOI is missing or blank, this returns the citation key.
61
+ # ":extension" Either of ".html" or "/index.html" depending upon the global permalink setting.
62
+ # Template parameters can also include any key defined in the bibtex file, e.g. ":year", ":title", etc.
63
+ # Bibtex keys such as 'title' are slugified in the same way as Jekyll treats blog post titles.
64
+ 'details_permalink' => '/:details_dir/:key:extension',
49
65
  'use_raw_bibtex_entry' => true,
50
66
 
51
67
  'bibliography_class' => 'bibliography',
@@ -5,10 +5,12 @@ module Jekyll
5
5
  include Scholar::Utilities
6
6
 
7
7
  def initialize(site, base, dir, entry)
8
- @site, @base, @dir = site, base, dir
8
+ @site, @base, @dir, @entry = site, base, dir, entry
9
9
 
10
10
  @config = Scholar.defaults.merge(site.config['scholar'] || {})
11
11
 
12
+ # Specify a temporary filename for now based upon the citation key. Jekyll
13
+ # will modify this according to the URL template below
12
14
  @name = entry.key.to_s.gsub(/[:\s]+/, '_')
13
15
  @name << '.html'
14
16
 
@@ -19,6 +21,10 @@ module Jekyll
19
21
  data['title'] = data['entry']['title'] if data['entry'].has_key?('title')
20
22
  end
21
23
 
24
+ def url
25
+ # Reuse the logic in the utilities module for deciding URLs
26
+ details_link_for(@entry)
27
+ end
22
28
  end
23
29
 
24
30
  class DetailsGenerator < Generator
@@ -563,20 +563,6 @@ module Jekyll
563
563
  site.layouts.key?(File.basename(config['details_layout'], '.html'))
564
564
  end
565
565
 
566
- def details_file_for(entry)
567
- name = entry.key.to_s.dup
568
-
569
- name.gsub!(/[:\s]+/, '_')
570
-
571
- if site.config['permalink'] == 'pretty'
572
- name << '/'
573
- elsif site.config['permalink'].end_with? '/'
574
- name << '/'
575
- else
576
- name << '.html'
577
- end
578
- end
579
-
580
566
  def repository_link_for(entry, base = base_url)
581
567
  name = entry.key.to_s.dup
582
568
  name.gsub!(/[:\s]+/, '_')
@@ -597,7 +583,37 @@ module Jekyll
597
583
  end
598
584
 
599
585
  def details_link_for(entry, base = base_url)
600
- File.join(base, details_path, details_file_for(entry))
586
+ # Expand the details_permalink template into the complete URL for this entry.
587
+
588
+ # First generate placeholders for all items in the bibtex entry
589
+ url_placeholders = {}
590
+ entry.fields.each_pair do |k, v|
591
+ value = v.to_s.dup
592
+ value = Jekyll::Utils::slugify(value, :mode => 'pretty') unless k == :doi
593
+ url_placeholders[k] = value
594
+ end
595
+ # Maintain the same URLs are previous versions of jekyll-scholar by replicating the way that it
596
+ # processed the key.
597
+ url_placeholders[:key] = entry.key.to_s.gsub(/[:\s]+/, '_')
598
+ url_placeholders[:details_dir] = details_path
599
+ # Autodetect the appropriate file extension based upon the site config, using the same rules as
600
+ # previous versions of jekyll-scholar. Uses can override these settings by defining a details_permalink
601
+ # without the :extension field.
602
+ if (site.config['permalink'] == 'pretty') || (site.config['permalink'].end_with? '/')
603
+ url_placeholders[:extension] = '/'
604
+ else
605
+ url_placeholders[:extension] = '.html'
606
+ end
607
+ # Overwrite the 'doi' key with the citation key if the DOI field is empty or missing
608
+ if !entry.has_field?('doi') || entry.doi.empty?
609
+ url_placeholders[:doi] = url_placeholders[:key]
610
+ end
611
+
612
+ # generate the URL
613
+ URL.new(
614
+ :template => config['details_permalink'],
615
+ :placeholders => url_placeholders
616
+ ).to_s
601
617
  end
602
618
 
603
619
  def base_url
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  class Scholar
3
- VERSION = '5.15.0'.freeze
3
+ VERSION = '5.16.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-scholar
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.15.0
4
+ version: 5.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvester Keil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-21 00:00:00.000000000 Z
11
+ date: 2019-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll