WIP: Need to make it work for 3.1.6 and without deprecation message

This commit is contained in:
Pixelastic 2016-07-01 17:50:40 +02:00
parent db1f95237e
commit dd31b0eb9c
10 changed files with 112 additions and 22 deletions

View File

@ -3,6 +3,6 @@ appraise 'jekyll-v2' do
end
appraise 'jekyll-v3' do
gem 'jekyll', '~> 3.0'
gem 'jekyll', '3.1.6'
gem 'jekyll-paginate', '~> 1.1.0'
end

View File

@ -9,7 +9,7 @@ gem "json", "~> 1.8"
gem "nokogiri", "~> 1.6"
gem "html-hierarchy-extractor", :path => "../../html-hierarchy-extractor/"
gem "verbal_expressions", "~> 0.1.5"
gem "jekyll", "~> 3.0"
gem "jekyll", "3.1.6"
gem "jekyll-paginate", "~> 1.1.0"
group :development do

View File

@ -67,12 +67,12 @@ class AlgoliaSearchRecordExtractor
extname = File.extname(basename)
slug = File.basename(basename, extname)
# Jekyll v2 posts have a specific slug method
return @file.slug if @file.respond_to? :slug
# Jekyll v3 posts have it in data
return @file.data['slug'] if @file.data.key?('slug')
# Jekyll v2 posts have a specific slug method
return @file.slug if @file.respond_to?(:slug)
slug
end
@ -81,11 +81,19 @@ class AlgoliaSearchRecordExtractor
def tags
tags = []
# Jekyll v2 posts have a specific tags methods
tags = @file.tags if @file.respond_to?(:tags)
is_v2 = AlgoliaSearchUtils.restrict_jekyll_version(less_than: '3.0')
is_v3 = AlgoliaSearchUtils.restrict_jekyll_version(more_than: '3.0')
has_tags_method = @file.respond_to?(:tags)
has_tags_data = @file.data.key?('tags')
# Others have it in data
tags = @file.data['tags'] if tags.empty? && @file.data.key?('tags')
# Starting from Jekyll v3, all tags are in data['tags']
tags = @file.data['tags'] if is_v3 && has_tags_data
# In Jekyll v2, tags are in data['tags'], or in .tags
if is_v2
tags = @file.tags if has_tags_method
tags = @file.data['tags'] if tags.empty? && has_tags_data
end
# Some extension extends the tags with custom classes, so we make sure we
# cast them as strings

View File

@ -1,5 +1,5 @@
collections:
my-collection:
api:
output: true
markdown_ext: 'md,mkd'
paginate: 1

View File

@ -0,0 +1,39 @@
---
title: API Entreprise
tagline: Simplifier les démarches des entreprises en récupérant pour elles leurs documents administratifs
doc_tech: https://api.apientreprise.fr/docs
domain: http://api.apientreprise.fr
contract: OUVERT sous contrat
stat:
lastXdays: 30
url: https://dashboard.apientreprise.fr/api/stats/apientreprise/last_30_days_requests
label: informations non redemandées aux entreprises
clients:
- Collectivités
- Administrations
- Ministères
- Places de marchés
partners:
- DGFiP
- ACOSS
- CNETP
- INSEE
- INFOGREFFE
- FNTP
- MSA
- OPQIBI
- PRO BTP
- QUALIBAT
- MIN INTERIEUR
owner: DINSIC
category: confidential
keywords:
- etablissement
- entreprise
- certification
access_link: https://tps.apientreprise.fr/users/dossiers/new?procedure_id=33
---
LAPIENTREPRISE est une plateforme déchange opérée par le SGMAP qui met à disposition des opérateurs publics et des administrations, des données et des documents administratifs de référence, relatifs aux entreprises et association, qui sont délivrés par les administrations et les organismes publics, à fin de simplifier les démarches administratives et la gestion des dossiers.
Composante de lEtat plateforme, laccès à lAPIENTREPRISE est modérée et régulée par le SGMAP, qui attribue à chaque client des autorisations de récupération dinformations selon la nature des démarches à traiter (Marchés publics simplifiés, aides publiques simplifiés…)

View File

@ -54,6 +54,7 @@ describe(AlgoliaSearchJekyllPush) do
end
it 'keeps markdown documents' do
ap document_file
expect(push.indexable?(document_file)).to eq true
end

View File

@ -14,15 +14,10 @@ describe(AlgoliaSearchRecordExtractor) do
let(:fixture_front_matter) do
extractor.new(site.file_by_name('front_matter.md'))
end
# let(:html_page_file) { extractor.new(site.file_by_name('authors.html')) }
# let(:hierarchy_page_file) {
# extractor.new(site.file_by_name('hierarchy.md'))
# }
# let(:weight_page_file) { extractor.new(site.file_by_name('weight.md')) }
before(:each) do
# Disabling the logs, while still allowing to spy them
Jekyll.logger = double('Specific Mock Logger').as_null_object
# Jekyll.logger = double('Specific Mock Logger').as_null_object
@logger = Jekyll.logger.writer
end
@ -152,6 +147,25 @@ describe(AlgoliaSearchRecordExtractor) do
expect(actual).to eq 'collection-item'
end
# if restrict_jekyll_version(more_than: '3.0')
# fit 'should not throw a deprecation warning' do
# # Given
# input = fixture_post
# # When
# # allow(Jekyll).to receive(:logger) do
# # double('AAA').as_null_object
# # end
# # Jekyll.logger = double('BBB').as_null_object
# # Jekyll.logger.writer = double('CCC').as_null_object
# actual = input.slug
# # expect(actual).to eq 'collection-item'
# end
# end
end
describe 'tags' do

View File

@ -34,16 +34,44 @@ def get_site(config = {}, options = {})
site = AlgoliaSearchJekyllPush.init_options({}, options, config)
.jekyll_new(config)
def site.file_by_name(file_name)
# We first check the exact match
# We build the list of all the files in the website. Starting from jekyll
# 1.3.4, collections are no longer returned by each_site_file.
files = {}
ap self
# Fails sur 1.3.6, marche sur 3.1.3
# Pour le moment on va rester à le faire marcher sur 3.1.3
# On va poser les tests pour s'assurer que jekyll 3 ne lance pas de warning
# de deprecation
# Une fois ok, on vérifie que api.gouv.fr fonctionne avec 1.3.6
# Si oui, on regarde comment ils passent les collections à la vue et on fait
# pareil pour chopper les documents
# Si non, on file un bug
# We get the list of all classic files
each_site_file do |file|
return file if file.path == file_name
files[file.path] = file
end
# Same for the collections
collections.each do |collection_name, items|
ap collection_name
items.each do |item|
files[item.path] = item
end
end
# If not found (happens for static files that uses a full absolute path), we
# try with a loose regexp
each_site_file do |file|
return file if file.path =~ /#{file_name}$/
# If we have an exact match, we use that one:
return files[file_name] if files.key?(file_name)
# Otherwise we try to find a key that is loosely matching
keys = files.keys
values = files.values
keys.each_with_index do |key, index|
return values[index] if key =~ /#{file_name}$/
end
nil