Giter VIP home page Giter VIP logo

jekyll-contentful-data-import's Introduction

Jekyll-Contentful-Data-Import

Build Status

Contentful provides a content infrastructure for digital teams to power content in websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship digital products faster.

Jekyll-Contentful-Data-Import is a Jekyll extension to use the Jekyll static site generator together with Contentful. It is powered by the Contentful Ruby Gem.

Experience the power of Jekyll while staying sane as a developer by letting end-users edit content in a web-based interface.

Installation

Create a Gemfile in your Jekyll project and add the following:

source 'https://rubygems.org'

group :jekyll_plugins do
  gem "jekyll-contentful-data-import"
end

Then as usual, run:

bundle install

Usage

Run jekyll contentful in your terminal. This will fetch entries for the configured spaces and content types and put the resulting data in the local data folder as yaml files.

--rebuild option

The contentful command has a --rebuild option which will trigger a rebuild of your site

Configuration

To configure the extension, add the following configuration block to Jekyll's _config.yml:

contentful:
  spaces:
    - example:                              # Jekyll _data folder identifier - Required
        space: cfexampleapi                 # Required
        access_token: b4c0n73n7fu1          # Required
        environment: master                 # Optional
        cda_query:                          # Optional
          include: 2
          limit: 100
        all_entries: true                   # Optional - Defaults to false, only grabbing the amount set on CDA Query
        all_entries_page_size: 1000         # Optional - Defaults to 1000, maximum amount of entries per CDA Request for all_entries
        content_types:                      # Optional
          cat: MyCoolMapper
        client_options:                     # Optional
          api_url: 'preview.contentful.com' # Defaults to 'api.contentful.com' which is Production
          max_include_resolution_depth: 5   # Optional - Defaults to 20, maximum amount of levels to resolve includes
        base_path: app_path                 # Optional - Defaults to Current directory
        destination: destination_in_data    # Optional - Defaults to _data/contentful/spaces
        individual_entry_files: true        # Optional - Defaults to false
        rich_text_mappings:                 # Optional - Defaults to {}
          embedded-entry-block: MyEntryRenderer
Parameter Description
space Contentful Space ID
access_token Contentful Delivery API access token
environment Space environment, defaults to master
cda_query Hash describing query configuration. See contentful.rb for more info (look for filter options there). Note that by default only 100 entries will be fetched, this can be configured to up to 1000 entries using the limit option.
all_entries Boolean, if true will run multiple queries to the API until it fetches all entries for the space
all_entries_page_size Integer, the amount of maximum entries per CDA Request when fetching :all_entries
content_types Hash describing the mapping applied to entries of the imported content types
client_options Hash describing Contentful::Client configuration. See contentful.rb for more info.
base_path String with path to your Jekyll Application, defaults to current directory. Path is relative to your current location.
destination String with path within _data under which to store the output yaml file. Defaults to contentful/spaces
individual_entry_files Boolean, if true will create an individual file per entry separated in folders by content type, file path will be {space_alias}/{content_type_id}/{entry_id}.yaml. Default behavior is to create a file per space. Usage is affected when this is set to true, please look in the section below.
rich_text_mappings Hash with 'nodeTyoe' => RendererClass pairs determining overrides for the RichTextRenderer library configuration.

You can add multiple spaces to your configuration

Entry mapping

The extension will transform every fetched entry before storing it as a yaml file in the local data folder. If a custom mapper is not specified a default one will be used.

The default mapper will map fields, assets and linked entries.

Custom Mappers

You can create your own mappers if you need to. The only requirement for a class to behave as a mapper is to have a map instance method.

Following is an example of such custom mapper that reverses all entry field IDs:

class MyReverseMapper < ::Jekyll::Contentful::Mappers::Base
  def map
    result = super
    reversed_result = {}

    result.each do |k, v|
      reversed_result[k.reverse] = v
    end

    reversed_result
  end
end

Caveats

Note: This has changed since previous version.

When creating custom mappers, you should create them in a file under #{source_dir}/_plugins/mappers/. This will allow the autoload mechanism that has been included in the latest version.

With the autoload mechanism, there is no longer a need to create a rake task for importing using custom mappers.

If you already have a custom rake task, the new autoload mechanism will not affect it from working as it was working previously.

Rich Text Beta

To render rich text in your views, you can use the rich_text filter:

{{ entry.rich_text_field | rich_text }}

This will output the generated HTML generated by the RichTextRenderer library.

Adding custom renderers

When using rich text, if you're planning to embed entries, then you need to create your custom renderer for them. You can read how create your own renderer classes here.

To configure the mappings, you need to add them in your contentful block like follows:

contentful:
  spaces:
    - example:
      # ... all the regular config ...
      rich_text_mappings:
        embedded-entry-block: MyCustomRenderer

You can also add renderers for all other types of nodes if you want to have more granular control over the rendering.

This will use the same autoload strategy included for custom entry mappers, therefore, you should include your mapper classes in #{source_dir}/_plugins/mappers/.

Using the helper with multiple Contentful spaces

In case you have multiple configured spaces, and have different mapping configurations for them. You can specify which space you want to pull the configuration from when using the helper.

The helper receives an additional optional parameter for the space name. By default it is nil, indicating the first available space.

So, if for example you have 2 spaces with different configurations, to use the space called foo, you should call the helper as: {{ entry.field | rich_text: "foo" }}.

Hiding Space and Access Token in Public Repositories

In most cases you may want to avoid including your credentials in publicly available sites, therefore you can do the following:

  1. bundle update โ€” make sure your gem version supports ENV_ variables

  2. Set up your _config like so:

contentful:
  spaces:
    - example:
        space:        ENV_CONTENTFUL_SPACE_ID
        access_token: ENV_CONTENTFUL_ACCESS_TOKEN
        environment:  ENV_CONTENTFUL_ENVIRONMENT

(Your Space ID will be looked upon on ENV['CONTENTFUL_SPACE_ID'], your Access Token on ENV['CONTENTFUL_ACCESS_TOKEN'] and your environment on ENV['CONTENTFUL_ENVIRONMENT'].)

  1. Either add the following variables to your shell's configuration file (.bashrc or .bash_profile, for example):
export CONTENTFUL_ACCESS_TOKEN=abc123
export CONTENTFUL_SPACE_ID=abc123
export CONTENTFUL_ENVIRONMENT=master

(And run source ~/.bashrc or open new terminal to enable changes.)

Or specify them on the command line:

CONTENTFUL_ACCESS_TOKEN=abc123 CONTENTFUL_SPACE_ID=abc123 CONTENTFUL_ENVIRONMENT=master jekyll contentful
  1. Party.

This way, it is safe to share your code without having to worry about your credentials.

Using Multiple Entry Files

When setting the individual_entry_files flag to true, the usage pattern changes a little, as Jekyll does not allow for variable unpacking when iterating.

A usage example is as follows:

<ul class="cat-list">
  <!-- Each element in the array of entries for a content type is an array of the form ['entry_id', { ... entry_data ...}] -->
  {% for cat_data in site.data.contentful.spaces.example.cat %}
    {% assign cat_id = cat_data[0] %} <!-- Entry ID is the first element of the array -->
    {% assign cat = cat_data[1] %} <!-- Entry data is the second element of the array -->
    <li>
      <p>{{ cat_id }}: {{ cat.name }}</p>
    </li>
  {% endfor %}
</ul>

Examples

You can find working examples of multiple uses here.

Contributing

Feel free to add your own examples by submitting a Pull Request. For more information, please check CONTRIBUTING.md

jekyll-contentful-data-import's People

Contributors

benaldred avatar dlitvakb avatar dskelton-cos avatar felixjung avatar iamalfonse avatar jckfa avatar loudmouth avatar mariobodemann avatar neonichu avatar roblinde avatar rubydog avatar ruderngespra avatar sheamunion avatar whaleen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jekyll-contentful-data-import's Issues

config path for .yaml file

it would be great to define in the jekyll contentful command a variable with the path where the .yaml will be generated, or use the _config.yml for that

I have the next line in my Jekyll config:

source: '_app'

so, after running the command I need to copy the resulting file

Individual posts not showing up in data folder

I set individual_entry_files to true, and ran jekyll contentful --rebuild but I still only have a single yaml file in my spaces directory. Is there some other step that I am missing?

Markdown not parsed well

Hello other Jekyll programmers,

I have a problem with contentful giving me Markdown as response (which is not a problem). But when I loop through the data and print the 'body"-field which is markdown Jekyll actually prints the raw data.


title: Blog

permalink: /blog

Blog Posts

    {% for post in site.data.contentful.spaces.site.blog-post %}
  • {{ post.body }}

  • {% endfor %}

subscribe via RSS

`

this will give me the following html:

`

    <li>
      <p>__Hello everyone,__
    

    yesterday was a beautiful day in Amsterdam @ straf_werk festival 2016.

    At first there was a littlebit rain, but then the sun came through and the sphere was nice.

    We've danced a lot and where back in Soest around 1 a.m.

    Theo.


    <li>
      <p>__Test Blog Post__
    

    just a lovely day in Berlin @ the bar.

    See you tomorrow.

    1. first
    2. second
    3. third
    4. fourth
    5. fifth
    6. sixth

    Community platform

    </li>
    
`

I hope someone could help me with this.

Theo

Missing entries in the imported yaml file

Any ideas why the yaml file would sometimes include an entry and later on randomly not include that same entry on subsequent imports.

We are experiencing this issue very regularly now. We have around 133 entries on Contentful that are published but not all of them are showing up in resulting yaml file. But if I go and make the missing entry Draft and then publish it again. It shows up in the yaml file.

Would really appreciate any help with this issue.

Error Importing Content

Having an issue running bundle exec jekyll conetntful

Keep getting jekyll 3.1.3 | Error: undefined method[]' for nil:NilClass`

Full trace:

bundle exec jekyll contentful --trace
Configuration file: /Users/leylandjacob/dev/clients/ROCKLIN/_config.yml
Starting Contentful import 
/Library/Ruby/Gems/2.0.0/gems/jekyll-contentful-data-import-1.2.1/lib/jekyll-contentful-data-import/importer.rb:16:in `block in run': undefined method `[]' for nil:NilClass (NoMethodError)
        from /Library/Ruby/Gems/2.0.0/gems/jekyll-contentful-data-import-1.2.1/lib/jekyll-contentful-data-import/importer.rb:14:in `each'
        from /Library/Ruby/Gems/2.0.0/gems/jekyll-contentful-data-import-1.2.1/lib/jekyll-contentful-data-import/importer.rb:14:in `run'
        from /Library/Ruby/Gems/2.0.0/gems/jekyll-contentful-data-import-1.2.1/lib/jekyll/commands/contentful.rb:30:in `process'
        from /Library/Ruby/Gems/2.0.0/gems/jekyll-contentful-data-import-1.2.1/lib/jekyll/commands/contentful.rb:15:in `block (2 levels) in init_with_program'
        from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `call'
        from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
        from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
        from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
        from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
        from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
        from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.1.3/bin/jekyll:13:in `<top (required)>'
        from /usr/local/bin/jekyll:23:in `load'
        from /usr/local/bin/jekyll:23:in `<main>'

Rich Text: Node Target Is Not An Asset

Hi,

I'm on Jekyll 3.8.6 (and 1.8.1 of jekyll-contentful-data-import) and I'm having trouble with rich_text fields. The rich_text fields work fine if there is no images in them. But if I add an image to the rich_text I start getting this error:

Liquid Exception: Node target is not an asset - Node: {"data"=>{"target"=>{"sys"=>{"id"=>"3AUkX9yyLz689tJQeshs0u", "created_at"=>2019-10-22 20:49:39 +0000, "updated_at"=>2019-10-22 20:49:39 +0000}, "title"=>"This is the Squarespace editor.", "description"=>nil, "url"=>"//images.ctfassets.net/fm8sawzb3em9/3AUkX9yyLz689tJQeshs0u/1c441b2d98d65b3b7797c165f2f44a6e/website-editor.jpeg"}}, "content"=>[], "nodeType"=>"embedded-asset-block"} in index.html

jekyll 3.8.6 | Error: Node target is not an asset - Node: {"data"=>{"target"=>{"sys"=>{"id"=>"3AUkX9yyLz689tJQeshs0u", "created_at"=>2019-10-22 20:49:39 +0000, "updated_at"=>2019-10-22 20:49:39 +0000}, "title"=>"This is the Squarespace editor.", "description"=>nil, "url"=>"//images.ctfassets.net/fm8sawzb3em9/3AUkX9yyLz689tJQeshs0u/1c441b2d98d65b3b7797c165f2f44a6e/website-editor.jpeg"}}, "content"=>[], "nodeType"=>"embedded-asset-block"}

Am I doing something wrong? I have the rich_text_renderer gem installed too. ๐Ÿค”

Reverse of this?

Is there a way to reverse this process and put data into Contentful from YAML files? I have an existing Jekyll blog I want to migrate to Contentful.

ENV_ variables usage

Hello,

thanks for the great work in this tool.
I have a question regarding PR #19, tried to set it up for a project of mine and I have this config set up: https://gist.github.com/martzoukos/1faece5f70e56ee57954d4116fce9bb4
and this .env file on my project's root folder: https://gist.github.com/martzoukos/1659a797ad15ff59d22bdb4f79f15be3

  • When I'm running jekyll contentful I get a jekyll 3.2.1 | Error: Contentful::Unauthorized error.
  • If I replace the ENV_CONTENTFUL_SPACE_ID and ENV_CONTENTFUL_ACCESS_TOKEN in the config with their values, then the fetch works.
  • I have gem 'dotenv-rails' in my gemfile

Is there something I'm missing in this setup?

Thank you in advance for your help.

Sorting when iterating

Hi,

I have a list of data objects and iterate over them like so:

{% for course_data in site.data.contentful.spaces.company.course %}
  {% assign title = course_data[1]['title'] %}

  <li>{{title}}</li>
{% endfor %}

This works great. However, the order in which the objects are listed depends on the ID value that each content object gets from Contentful.

These look like this for example:

ID: 1m3ap... Title: Open...
ID: 5kFqz... Title: Agile...
ID: UL3CJ... Title: Infrastructure...

Therefore, the list looks as follows:

  • Open
  • Agile
  • Infrastructure

What I would like is and alphabetical order:

  • Agile
  • Infrastructure
  • Open

Is there a way that I can bring order into the iteration?

Maybe I can use the title field as the ID of the object?
That would also solve this problem for me:
#57

Unclear how to do rich_text_mappings

I am having a really hard time making sense of the documentation on how to get rich_text_mappings working. Below is what I have done, but nothing seems to happen, I just get the full entry JSON printed, not the entry.content_type_id, any guidance would be much appreciated.

Config.yml

page_gen:
  - index_files: true
    data: "contentful.spaces.site.blogPost"
    template: "custom-post"
    name: "slug"
    dir: "blog"
    extension: "html"
    rich_text_mappings:
      embedded-entry-block: QcEntryBlockRenderer

_plugins/mappers/QcEntryBlockRenderer.rb

class QcEntryBlockRenderer < RichTextRenderer::BaseNodeRenderer
  def render(node)
    entry = node['data']['target']

    "<code><pre>{{ entry.content_type_id | jsonify }}</pre></code>"
  end
end

looking at this documentation and trying to match with rich-text-renderer I don't know if I need, or not:

renderer = RichTextRenderer::Renderer.new(
  'embedded-entry-block' => MyEntryBlockRenderer
)

Memory issues?

Hi there!

I'm experiencing issues running Jekyll::Commands::Contentful.process([], {}, Jekyll.configuration['contentful']) on CircleCI:

Starting Contentful import
Exited with code 137

Hint: Exit code 137 typically means the process is killed because it was running out of memory
Hint: Check if you can optimize the memory usage in your app
Hint: Max memory usage of this container is 4287877120
 according to /sys/fs/cgroup/memory/memory.max_usage_in_bytes

Running the same locally with the activity monitor open, I see the ruby process consuming a lot of memory as well upon running jekyll contentful (gradually builds up to 4GB!)...
You could think the Contentful space/environment I'm importing from has loads of entries/assets, however, that is not the case: it's only a handful of entries and a couple of assets!

Any help/reference to code that could be optimized for memory purposes in the importer appreciated!

Thanks in advance!
David

P.S. This is making use of v1.7.0 - 1.8.0 is awkwardly complaining upon import (Error: undefined method[]' for nil:NilClass`), even though the _config.yml hasn't changed from v1.7.0 usage... (this is obviously a separate issue)

SSL Error

Trying to follow the instructions for getting started. And I am getting the following error when running 'jekyll contentful'.

jekyll 3.5.2 | Error: SSL_connect returned=1 errno=0 state=error: certificate verify failed

Its a fairly simple jekyll project, and I am on Windows 10 with gem 2.4.5.2

Delay Between Change and Import

If I publish a change on Contentful, it takes at least 20 seconds for jekyll contentful to yield that change in the resulting data file.

In production, my site is set up to build immediately after a change is made. This 20 second delay is a problem as the build process will finish well before jekyll contentful has a chance to update the data. I can delay the build 30 seconds before executing, but that's not ideal.

I understand this is probably an issue with the Contentful Content Delivery API, but I guess what I'm asking is... is this even an issue or just how the thing works? Pardon my ignorance.

Data from referenced content type is separated

Hi, I don't know if this is a mapping issue (I've never done any custom mapping before) but here's where I'm at:

I have a Article content type that references an Author content type (allowing multiple authors).
When I import the data, this is what I get:


---
article:
- sys:
    id: ...
  title: ...
  author:
  - sys:
      id: ...
  - sys:
      id: ...
  body: ...

author:
- sys:
    id: ...
  name: ...
  dob: ...
- sys:
    id: ...
  name: ...
  dob: ...

The author fields "name" and "dob" are not inside article.

I need the data to format like this:


---
article:
- sys:
    id: ...
  title: ...
  author:
  - sys:
      id: ...
    name: ...
    dob: ...
  - sys:
      id: ...
    name: ...
    dob: ...
  body: ...

That way, I can fetch the data of each author within a particular article.

Individual posts not being created

Hey there! Not sure what I am missing but its clearly something! I have individual_entry_files: true in my config.yml file and I am able to successfully import data into the data directory however from there nothing happens. I can loop the data but I need physical files created for each post in the data yml file. Is there something more needed? Thanks!

Data strings that contain both : (colons) and ' (apostrophe) cause issues with data import

Problem: When importing data, any text data that contains both a colon and an apostrophe in the same text data, it causes an error when importing due to the way yaml files are created.

To Produce:

  • In Contentful, create a Content Model with a Short text field. Save it.
  • Then create a new Content using that Content Model.
  • In the Short text field, type any string that contains both a colon (:) and and apostrophe (') in the text field. Example: "Awesome: This isn't going to work because it has a colon and an apostrophe". Save it.
  • In Jekyll, do a data import in terminal using jekyll contentful or bundle exec jekyll contentful if using bundler.
  • The data will get imported, but the colons and/or apostrophe is not escaped, so any text after will not display correctly when adding it to a page.
  • Note: if text input ONLY has a colon or ONLY has an apostrophe, it get's escaped correctly. It only errors out when both are added to the text input string.

Possible fix:

  • Escape all colons and apostrophes during data import

Support for importing entry snapshots

We have received guidance per GDPR requirements to expose the revisions of our TOC document. This raises an interesting use case where we import the revisions of each entry and render them in our jekyll site as a log alongside the published entry.

Since this plugin only deals with the content delivery API, is it a reasonable feature request to fetch snapshots from the content management API?

Within the current configuration we could add a few parameters for fetching snapshots:

snapshots: true
snapshots_page_size: 1000

Any suggestions on this use case are welcome.

Slow Contentful Import

I have noticed since the last 4 days ago our Jekyll Contentful imports are taking extremely long.
On Netlify build servers and locally.

  • Using contentful 2.1.3
  • Using jekyll-contentful-data-import 1.6.0
  • Starting Contentful import
  • Killed
  • Finished 'contentfulDump' after 5.95 min

How to handle blog posts

Is it possible to generate individual posts with the filename in YEAR-MONTH-DAY-title.MARKUP format?

I understand that now we can generate individual files but I don't see an option for specifying the format of the filename and choosing the destination outside of data folder. With this last missing piece, I think we would be able to use contentful data to generate blog posts.

If it is not the suggested approach than how are people handling blog posts with contentful data?

Liquid syntax error when accessing data objects where ID starts with a number

Hi,

I am getting warning from Jekyll when accessing data objects where the ID begins with a number.

I am using them like this:

{% assign contentful_data = site.data.contentful.spaces.company.course.6MAMEasi0EiqKWSKeSaUIs %}

And I see this warning in the CLI output when running jekyll serve:

Liquid Warning: Liquid syntax error (line 1): Expected id but found number in "{{site.data.contentful.spaces.company.course.6MAMEasi0EiqKWSKeSaUIs }}" in index.html

No problem when the ID starts with a letter.

Maybe we could define a specific content model field as the ID?

Localized Assets

Getting the following error:

I am using contentful together with commercelayer and jekyll

jekyll 3.8.5 | Error: undefined method `each' for nil:NilClass


contentful:
  spaces:
    - en-US:
        space: xxx
        access_token: xxxx
        all_entries: true
        cda_query:
          locale: "en-US"
        client_options:
          default_locale: 'en-US'
    - it:
        space: xxx
        access_token: xxx
        all_entries: true
        cda_query:
          locale: "it"
        client_options:
          default_locale: 'en-US' 

Any ideas?

Support for Jekyll 4.0.0

I was trying to test this but, unless I am mistaken, it appears that it isn't compatible with the recent Jekyll 4.0.0 release yet.

Hide api key in public repository

Jekyll contentful plugin is configured in the config.yml file. But if I publish the repo on a public github repository, the api key will be available for anyone to use it.

'for' tag was never closed in /_layouts/home.html

When running jekyll serve i get the following.
Liquid Exception: Liquid syntax error (line 4): 'for' tag was never closed in /_layouts/home.html

I'm not sure how the for tag isn't closed when clearly it appears to be closed here

---
layout: default
---
<!-- Posts -->
<div class="jumbotron">
  <div class="container">
         {% for link in site.data.contentful.spaces.links.link %}
        <dt id="postPadd" class="list-group-item">
            <h1 id="t-pad">
              <a class="post-link text-primary" href="{{ link.url | relative_url }}">{{ link.title | escape }}</a>
            </h1>
            <div class="container">
              <span class="post-meta">Published <mark>{{ link.date | date: "%b %-d, %Y" }}</mark></span>
                <p class="rss-subscribe"><a href="{{ "/feed.xml" | relative_url }}">Subscribe</a></p>
                <div class="col-sm-8 col-med-8">
                    <img id="img-pad" class="img-fluid img" src="{{ site.baseurl }}assets/{{ link.image }}" />
                    <h5 id="exc-pad">{{ post.excerpt }}</h5>
                    <a id="btn-marg" href="{{ link.url | relative_url }}" class="btn btn-info btn-md active" role="button" aria-pressed="true">Read Now</a>
                </div>
            </div>  
        </dt>
          {% endfor %}
     </div>
</div>

Is there something that I am missing ?

Retrieving assets?

Is it possible to retrieve all assets in a space? I can't seem to find an example indicating how to do that.

Thanks!

Is it possible to use includes for rich-text content types?

I have a bunch of components that I am using includes for through out my site, however I'm porting over the blog to contentful and it uses some of these blocks. Rather than duplicate the code I'd prefer to use includes with in the renderer something like this:

class EntryBlockRenderer < RichTextRenderer::BaseNodeRenderer
  def render(node)
    
    entry = node['data']['target']
    sys = entry['sys']
    content_type = sys['content_type_id']
   
    if content_type == 'media'
      "{% include components/media-item.html title=#{entry['title']}  link=#{entry['link']} date=#{entry['publish_date']}  %}"
    elsif content_type == 'codeBlock'
      "{% include components/code.html code="<p>test</p>" lang="html" %}"
    else
       "<div>#{content_type_id}</div>"
    end
  end
end

Currently this just renders the includes as a string {% include components/media-item.html title=#{entry['title']} link=#{entry['link']} date=#{entry['publish_date']} %} rather than the actual include code.

Is it possible to do this?

Require mappers automatically

It'd be great to be able to use custom mappers without also needing to switch from the jekyll contentful command to a Rake task; is there any reason not to automatically require mappers from the _plugins directory?

Following the example of Jekyll::PluginManager, it seems it could be as simple as this:

def require_mappers(config)
  mapper_search_path = File.join(config["source"], config["plugins_dir"], "mappers")
  mapper_files = Jekyll::Utils.safe_glob(mapper_search_path, File.join("**", "*.rb"))
  Jekyll::External.require_with_graceful_fail(mapper_files)
end

This uses the source and plugins_dir values returned by Jekyll.configuration in the command file, so one option is to put this code there, but I imagine it might be better to put it in the Base mapper, next to mapper_for. The only catch is that would require some minor refactoring to Importer, since it currently expects only the contentful key of Jekyll.configuration.

Let me know what you think! I'd be glad to submit a PR.

Conflicts with Jekyll-Assets

When enabling both gem 'jekyll-contentful-data-import' and gem 'jekyll-assets' I get this error:

Error: 822: unexpected token at '

<title>400 Bad Request</title>

400 Bad Request


nginx

However both plugins work as expected when enabled independently. Here is the installed versions.
Using jekyll 3.3.0
Using contentful 1.2.1
Using jekyll-assets 2.2.8
Using jekyll-contentful-data-import 1.4.3

Add keys to collection of each content_type

Currently, each content_type is placed in an collection, but without any keys. Would it be possible to get the collection indexed by entry title, so that we can cherry pick a particular entry?

environment variables

It looks like environment variables can be used in my_website field, but not in client_options fields. So it's needed to use two config files to be able to change the environment (like master/staging). It can be done, but it would be great if it was possible to use a single config file, plus environment variables to achieve this.

  • my_website:
    space: ENV_CONTENTFUL_SPACE_ID
    access_token: ENV_CONTENTFUL_ACCESS_TOKEN
    client_options:
    environment: staging
    space: ENV_CONTENTFUL_SPACE_ID
    access_token: ENV_CONTENTFUL_ACCESS_TOKEN

Blank draft copies will error out preview imports

Getting the following error:

jekyll 3.3.0 | Error: undefined method `each' for nil:NilClass

As near as I can figure, any new records that are left empty will cause this import error. Contentful auto-saves drafts so its not hard to generate a blank record here and there.

Otherwise, I love this Gem. Great job contentful team!

Import date says tomorrow

A post I wrote ~11PM EST was imported as the next day ~3AM.

Is there a setting I'm missing to tweak this to import at my current timezone?

~Corey

Enable this gem for Github Pages

Hi,

I really love your Service and the Jekyll integration. What I miss is using this plugin on GitHub for creating my Site. As far as I understood GitHub has to add this to their plugins whitelist. Is there a workaround?

Error importing

Hey there!

I installed the modules and set up my _config.yml file. Everything seems to look good there, but when I run jekyll contentful, I receive the following error:

Starting Contentful import
jekyll 3.2.1 | Error:  The resource could not be found.

Let me know if you need me to provide any additional info. Thanks again!

Cannot reduce resolution depth

Regardless of what parameters I try, I cannot reduce the resolution depth. All changes result in the exact same file size.

I'm trying to solve the A links to B, B links to A recursion problem as noted here: contentful/contentful_model#111

It's not obvious if these properties work together, or cancel each other out.

contentful_options: &contentful_options
  cda_query:
    include: 2
    limit: 1000
  all_entries: true

contentful:
  spaces:
    -
      pec_staging:
        <<: *contentful_options
        client_options:
          api_url: 'preview.contentful.com'
          max_include_resolution_depth: 2

These are the version I am using:

contentful (0.12.0)
contentful-management (2.6.0)
jekyll (3.7.3)
jekyll-assets (2.2.8)

Feature Request: Generate separate markdown files per entry

The existing importer is great and works fine as it is. But for creating a more flexible website based on Contentful data, some features are not possible by a single large data yaml file. Specially it is a URL generation by Jekyll (without special plugins).

Therefor I have something like that in mind:

  • configure per content type if it should be rendered in a large yaml data file or in separate markdown files
  • for markdownfiles define
    ** location to same the files, e.g. /teammembers/_posts/
    ** Contentful field for usage as markdown content
    ** Contentful field for the date within the markdown filename
    ** template key/value pairs for yaml (e.g. Jekyll typical layout property)
    ** simplification for references used as Jekyll category and tag (e.g. by a configuration of Contenful fields used for tags and categories and than reduce the reference entries to eliminate ids)

Locales missing in yaml file

Hi there!

just grabbed this great gem and added it to our Jekyll project.

I got content in contentful translated in 2 locales but only get the default locale in the content import..

Anyone else got this and knows what to do?

Hide api key in public repository

Jekyll contentful plugin is configured in the config.yml file. But if I publish the repo on a public github repository, the api key will be available for anyone to use it.

Non-localized assets seem broken

Hey,

I don't know what happened, but somehow over the past week our build broke. I can't recall updating any dependencies, but we keep getting

NoMethodError: undefined method `[]=' for nil:NilClass

when trying to fetch from our space.

Doing some digging with pry I was able to localize the source of this issue at contentful.rb/lib/contentful/asset.rb#79:

@fields[default_locale][:file] = ::Contentful::File.new(file_json)

For some of our assets used in non-localized entries, @fields[default_locale] is nil, causing this line to fail. I don't understand the default locale is nil, as I would have thought the FieldsResource constructor should take care of initializing the default localization, no?

Is this maybe caused by us filtering for the locale we want to work on in the configuration of the Jekyll plugin?

  spaces:
    - de-DE:
        space: "xxx"
        access_token: "xxx"
        all_entries: true
        all_entries_page_size: 1000
        cda_query:
          include: 2
          limit: 100
          locale: "de-DE"
        client_options:
          api_url: "cdn.contentful.com"
        destination: "contentful"

I tried to quick-and-dirty patch this issue by either ensuring the @fields[default_locale] is initialized to an empty hash, if nil, or by directly setting @fields[:file] instead. Both ended up causing the following error:

NoMethodError: undefined method `url' for #<Hash:0x007fe13bb2c338>
  /usr/local/lib/ruby/gems/2.4.0/gems/jekyll-contentful-data-import-1.5.0/lib/jekyll-contentful-data-import/mappers/base.rb:119:in `map_asset'

Any idea what's going on?

Error Pulling In Data

I'm new to Jekyll and Contentful, so hang with me as I figure this out :)

I'm running a new install of Jekyll 3.1.6 locally and when running jekyll contentful I'm getting the following error:
/Library/Ruby/Gems/2.0.0/gems/jekyll-contentful-data-import-1.2.1/lib/jekyll-contentful-data-import/mappers/base.rb:82: stack level too deep (SystemStackError)

I'd really appreciate any help/advice on getting this error resolved. Thank you!

No support for rich text data type?

Jeez this took a while to debug. Apparently richtext field type is not supported.

RichText
Traceback (most recent call last):
	33: from /Users/soggie/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `<main>'
	32: from /Users/soggie/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `eval'
	31: from /Users/soggie/.rvm/gems/ruby-2.5.3/bin/jekyll:23:in `<main>'
	30: from /Users/soggie/.rvm/gems/ruby-2.5.3/bin/jekyll:23:in `load'
	29: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/jekyll-3.8.6/exe/jekyll:15:in `<top (required)>'
	28: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
	27: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
	26: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
	25: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
	24: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
	23: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/jekyll-contentful-data-import-1.8.1/lib/jekyll/commands/contentful.rb:33:in `block in command_action'
	22: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/jekyll-contentful-data-import-1.8.1/lib/jekyll/commands/contentful.rb:40:in `process'
	21: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/jekyll-contentful-data-import-1.8.1/lib/jekyll-contentful-data-import/importer.rb:21:in `run'
	20: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/jekyll-contentful-data-import-1.8.1/lib/jekyll-contentful-data-import/importer.rb:21:in `each'
	19: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/jekyll-contentful-data-import-1.8.1/lib/jekyll-contentful-data-import/importer.rb:29:in `block in run'
	18: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/jekyll-contentful-data-import-1.8.1/lib/jekyll-contentful-data-import/importer.rb:34:in `export_data'
	17: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/jekyll-contentful-data-import-1.8.1/lib/jekyll-contentful-data-import/importer.rb:79:in `get_entries'
	16: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/client.rb:168:in `entries'
	15: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/request.rb:30:in `get'
	14: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/client.rb:308:in `get'
	13: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/client.rb:371:in `do_build_resource'
	12: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/resource_builder.rb:52:in `run'
	11: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/resource_builder.rb:64:in `build_array'
	10: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/resource_builder.rb:64:in `map'
	 9: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/resource_builder.rb:66:in `block in build_array'
	 8: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/resource_builder.rb:90:in `build_item'
	 7: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/resource_builder.rb:90:in `new'
	 6: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/fields_resource.rb:14:in `initialize'
	 5: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/fields_resource.rb:128:in `hydrate_fields'
	 4: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/fields_resource.rb:108:in `hydrate_nonlocalized_fields'
	 3: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/fields_resource.rb:108:in `each'
	 2: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/fields_resource.rb:110:in `block in hydrate_nonlocalized_fields'
	 1: from /Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/entry.rb:29:in `coerce'
/Users/soggie/.rvm/gems/ruby-2.5.3/gems/contentful-2.6.0/lib/contentful/field.rb:45:in `coerce': undefined method `new' for nil:NilClass (NoMethodError)

Tracing KNOWN_TYPES gives me:

{"String":"Contentful::StringCoercion","Text":"Contentful::TextCoercion","Symbol":"Contentful::SymbolCoercion","Integer":"Contentful::IntegerCoercion","Number":"Contentful::FloatCoercion","Boolean":"Contentful::BooleanCoercion","Date":"Contentful::DateCoercion","Location":"Contentful::LocationCoercion","Object":"Contentful::ObjectCoercion","Array":"Contentful::ArrayCoercion","Link":"Contentful::LinkCoercion"}

As you can see, richtext is not one of the known types. Also, there should be better error handling there.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.