WIP: Need to make it work for 3.1.6 and without deprecation message
This commit is contained in:
		
							parent
							
								
									db1f95237e
								
							
						
					
					
						commit
						dd31b0eb9c
					
				| @ -3,6 +3,6 @@ appraise 'jekyll-v2' do | |||||||
| end | end | ||||||
| 
 | 
 | ||||||
| appraise 'jekyll-v3' do | appraise 'jekyll-v3' do | ||||||
|   gem 'jekyll', '~> 3.0' |   gem 'jekyll', '3.1.6' | ||||||
|   gem 'jekyll-paginate', '~> 1.1.0' |   gem 'jekyll-paginate', '~> 1.1.0' | ||||||
| end | end | ||||||
|  | |||||||
| @ -9,7 +9,7 @@ gem "json", "~> 1.8" | |||||||
| gem "nokogiri", "~> 1.6" | gem "nokogiri", "~> 1.6" | ||||||
| gem "html-hierarchy-extractor", :path => "../../html-hierarchy-extractor/" | gem "html-hierarchy-extractor", :path => "../../html-hierarchy-extractor/" | ||||||
| gem "verbal_expressions", "~> 0.1.5" | gem "verbal_expressions", "~> 0.1.5" | ||||||
| gem "jekyll", "~> 3.0" | gem "jekyll", "3.1.6" | ||||||
| gem "jekyll-paginate", "~> 1.1.0" | gem "jekyll-paginate", "~> 1.1.0" | ||||||
| 
 | 
 | ||||||
| group :development do | group :development do | ||||||
|  | |||||||
| @ -67,12 +67,12 @@ class AlgoliaSearchRecordExtractor | |||||||
|     extname = File.extname(basename) |     extname = File.extname(basename) | ||||||
|     slug = File.basename(basename, extname) |     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 |     # Jekyll v3 posts have it in data | ||||||
|     return @file.data['slug'] if @file.data.key?('slug') |     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 |     slug | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
| @ -81,11 +81,19 @@ class AlgoliaSearchRecordExtractor | |||||||
|   def tags |   def tags | ||||||
|     tags = [] |     tags = [] | ||||||
| 
 | 
 | ||||||
|     # Jekyll v2 posts have a specific tags methods |     is_v2 = AlgoliaSearchUtils.restrict_jekyll_version(less_than: '3.0') | ||||||
|     tags = @file.tags if @file.respond_to?(:tags) |     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 |     # Starting from Jekyll v3, all tags are in data['tags'] | ||||||
|     tags = @file.data['tags'] if tags.empty? && @file.data.key?('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 |     # Some extension extends the tags with custom classes, so we make sure we | ||||||
|     # cast them as strings |     # cast them as strings | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								spec/fixtures/jekyll_version_3/_config.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								spec/fixtures/jekyll_version_3/_config.yml
									
									
									
									
										vendored
									
									
								
							| @ -1,5 +1,5 @@ | |||||||
| collections: | collections: | ||||||
|   my-collection: |   api: | ||||||
|     output: true |     output: true | ||||||
| markdown_ext: 'md,mkd' | markdown_ext: 'md,mkd' | ||||||
| paginate: 1 | paginate: 1 | ||||||
|  | |||||||
							
								
								
									
										39
									
								
								spec/fixtures/jekyll_version_3/entreprise.md
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								spec/fixtures/jekyll_version_3/entreprise.md
									
									
									
									
										vendored
									
									
										Normal 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 | ||||||
|  | --- | ||||||
|  | 
 | ||||||
|  | L’APIENTREPRISE 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 l’Etat plateforme, l’accès à l’APIENTREPRISE est modérée et régulée par le SGMAP, qui attribue à chaque client des autorisations de récupération d’informations selon la nature des démarches à traiter (Marchés publics simplifiés, aides publiques simplifiés…) | ||||||
| @ -54,6 +54,7 @@ describe(AlgoliaSearchJekyllPush) do | |||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     it 'keeps markdown documents' do |     it 'keeps markdown documents' do | ||||||
|  |       ap document_file | ||||||
|       expect(push.indexable?(document_file)).to eq true |       expect(push.indexable?(document_file)).to eq true | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -14,15 +14,10 @@ describe(AlgoliaSearchRecordExtractor) do | |||||||
|   let(:fixture_front_matter) do |   let(:fixture_front_matter) do | ||||||
|     extractor.new(site.file_by_name('front_matter.md')) |     extractor.new(site.file_by_name('front_matter.md')) | ||||||
|   end |   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 |   before(:each) do | ||||||
|     # Disabling the logs, while still allowing to spy them |     # 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 |     @logger = Jekyll.logger.writer | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
| @ -152,6 +147,25 @@ describe(AlgoliaSearchRecordExtractor) do | |||||||
| 
 | 
 | ||||||
|       expect(actual).to eq 'collection-item' |       expect(actual).to eq 'collection-item' | ||||||
|     end |     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 |   end | ||||||
| 
 | 
 | ||||||
|   describe 'tags' do |   describe 'tags' do | ||||||
|  | |||||||
| @ -34,16 +34,44 @@ def get_site(config = {}, options = {}) | |||||||
|   site = AlgoliaSearchJekyllPush.init_options({}, options, config) |   site = AlgoliaSearchJekyllPush.init_options({}, options, config) | ||||||
|                                 .jekyll_new(config) |                                 .jekyll_new(config) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|   def site.file_by_name(file_name) |   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| |     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 |     end | ||||||
| 
 | 
 | ||||||
|     # If not found (happens for static files that uses a full absolute path), we |     # If we have an exact match, we use that one: | ||||||
|     # try with a loose regexp |     return files[file_name] if files.key?(file_name) | ||||||
|     each_site_file do |file| | 
 | ||||||
|       return file if file.path =~ /#{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 |     end | ||||||
| 
 | 
 | ||||||
|     nil |     nil | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user