jekyll-airtable-import 0.1.0 → 0.1.1
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/README.md +2 -0
- data/lib/jekyll-airtable-import.rb +31 -8
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2589b20a661dd6d0b89a961f8389f57e6d6ad24a30528734f9a9e53e578cb35d
         | 
| 4 | 
            +
              data.tar.gz: 838e33e8b15453a6323193b3cfc68b0045b047a526ad7d364645c1db7baff9e7
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 6e213d5dfb5127468bcf72b3d853b2ef89545823ffcdbfee898f160e44c4bf2db3dfbf2651bb0ca93ea49df94edb2c3a068778672d864eba54ab6982cd589510
         | 
| 7 | 
            +
              data.tar.gz: cd72fe3032c1b2f7146aecae51d4ba97f74f4f8fa169806b24fbc240c3c66412ecdc4c8dee9e0a320b94ea4699a265c5d9bd0dc0060aba45d3bdcdb5c24ac4b3
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,5 +1,7 @@ | |
| 1 1 | 
             
            # Jekyll Airtable importer
         | 
| 2 2 |  | 
| 3 | 
            +
            [](https://badge.fury.io/rb/jekyll-airtable-import)
         | 
| 4 | 
            +
             | 
| 3 5 | 
             
            A simple plugin that used the [Airtable gem](https://rubygems.org/gems/airtable)
         | 
| 4 6 | 
             
            create data or collections in Jekyll.
         | 
| 5 7 |  | 
| @@ -9,14 +9,22 @@ module Airtable | |
| 9 9 | 
             
              class Generator < ::Jekyll::Generator
         | 
| 10 10 | 
             
                priority :medium
         | 
| 11 11 |  | 
| 12 | 
            -
                def  | 
| 12 | 
            +
                def parse_airtable_data(data)
         | 
| 13 13 | 
             
                  data_parse = []
         | 
| 14 14 | 
             
                  data.each do |item|
         | 
| 15 15 | 
             
                    # Extract attachments to just their URL
         | 
| 16 16 | 
             
                    item.each do |key,val|
         | 
| 17 17 | 
             
                      if val.kind_of?(Array)
         | 
| 18 18 | 
             
                        if val[0]['url']
         | 
| 19 | 
            -
                           | 
| 19 | 
            +
                          if val.length == 1
         | 
| 20 | 
            +
                            item[key] = val[0]['url']
         | 
| 21 | 
            +
                          else
         | 
| 22 | 
            +
                            item[key] = []
         | 
| 23 | 
            +
                          end
         | 
| 24 | 
            +
                          val.each do | asset |
         | 
| 25 | 
            +
                            item[key] << asset['url']
         | 
| 26 | 
            +
                          end
         | 
| 27 | 
            +
             | 
| 20 28 | 
             
                        end
         | 
| 21 29 | 
             
                      end
         | 
| 22 30 | 
             
                    end
         | 
| @@ -24,36 +32,51 @@ module Airtable | |
| 24 32 | 
             
                  end
         | 
| 25 33 | 
             
                  data_parse
         | 
| 26 34 | 
             
                end
         | 
| 35 | 
            +
             | 
| 27 36 | 
             
                def generate(site)
         | 
| 28 37 | 
             
                  return unless site.config['airtable']
         | 
| 29 38 | 
             
                  # Get API key from environment
         | 
| 30 39 | 
             
                  if ENV['AIRTABLE_API_KEY']
         | 
| 31 40 | 
             
                    api_key = ENV['AIRTABLE_API_KEY']
         | 
| 32 41 | 
             
                  else
         | 
| 33 | 
            -
                    warn "No  | 
| 42 | 
            +
                    Jekyll.logger.warn "No Airtable api key found. Make sure your key is available as AIRTABLE_API_KEY in the local environment."
         | 
| 43 | 
            +
                    return
         | 
| 34 44 | 
             
                  end
         | 
| 35 45 | 
             
                  # Pass in api key to client
         | 
| 36 46 | 
             
                  @client = Airtable::Client.new(api_key)
         | 
| 47 | 
            +
                  @app_id = nil
         | 
| 48 | 
            +
                  @table_id = nil
         | 
| 37 49 | 
             
                  site.config['airtable'].each do |name, conf|
         | 
| 50 | 
            +
                    if conf['app']
         | 
| 51 | 
            +
                      @app_id = conf['app'] # Only update app if conf does
         | 
| 52 | 
            +
                    end
         | 
| 53 | 
            +
                    unless @app_id
         | 
| 54 | 
            +
                      Jekyll.logger.warn "No app ID for Airtable import of " + name
         | 
| 55 | 
            +
                      next
         | 
| 56 | 
            +
                    end
         | 
| 57 | 
            +
                    @table_id = conf['table'] if conf['table']
         | 
| 58 | 
            +
                    unless @table_id
         | 
| 59 | 
            +
                      Jekyll.logger.warn "No table ID for Airtable import of " + name
         | 
| 60 | 
            +
                      next
         | 
| 61 | 
            +
                    end
         | 
| 38 62 | 
             
                    # Pass in the app key and table name
         | 
| 39 | 
            -
                    @table = @client.table( | 
| 63 | 
            +
                    @table = @client.table(@app_id, @table_id)
         | 
| 40 64 | 
             
                    # Get records where the Published field is checked
         | 
| 41 65 | 
             
                    @records = @table.all(:view => conf['view'],:fields => conf['fields'])
         | 
| 42 66 | 
             
                    # Extract data to a hash
         | 
| 43 67 | 
             
                    data = @records.map { |record| record.attributes }
         | 
| 44 | 
            -
                    parsed_data =  | 
| 68 | 
            +
                    parsed_data = parse_airtable_data(data)
         | 
| 45 69 | 
             
                    if conf['collection']
         | 
| 46 70 | 
             
                      slug_field = conf['collection']['slug']
         | 
| 47 | 
            -
                      layout = conf['collection']['layout']
         | 
| 71 | 
            +
                      layout = conf['collection']['layout'] || name
         | 
| 48 72 | 
             
                      if site.collections[name]
         | 
| 49 73 | 
             
                        new_collection = site.collections[name]
         | 
| 50 74 | 
             
                      else
         | 
| 51 75 | 
             
                        new_collection = Jekyll::Collection.new(site, name)
         | 
| 52 76 | 
             
                      end
         | 
| 53 | 
            -
                      # new_collection = Jekyll::Collection.new(site, name)
         | 
| 54 77 | 
             
                      parsed_data.each do |item|
         | 
| 55 78 | 
             
                        if item[slug_field] and item[slug_field] != ''
         | 
| 56 | 
            -
                          content = item[conf['collection']['content']]
         | 
| 79 | 
            +
                          content = item[conf['collection']['content'] || 'content']
         | 
| 57 80 | 
             
                          #puts content
         | 
| 58 81 | 
             
                          slug = Jekyll::Utils.slugify(item[slug_field])
         | 
| 59 82 | 
             
                          path = File.join(site.source, "_#{name}", "#{slug}.md")
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: jekyll-airtable-import
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - joe-irving
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2021- | 
| 11 | 
            +
            date: 2021-11-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: jekyll
         | 
| @@ -69,7 +69,7 @@ files: | |
| 69 69 | 
             
            - LICENSE.txt
         | 
| 70 70 | 
             
            - README.md
         | 
| 71 71 | 
             
            - lib/jekyll-airtable-import.rb
         | 
| 72 | 
            -
            homepage: https:// | 
| 72 | 
            +
            homepage: https://github.com/tippingpointuk/jekyll-airtable-import/
         | 
| 73 73 | 
             
            licenses:
         | 
| 74 74 | 
             
            - MIT
         | 
| 75 75 | 
             
            metadata: {}
         |