This repository has been archived by the owner on May 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
803 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'structured_text_renderer' | ||
|
||
module Jekyll | ||
module Contentful | ||
# Liquid filter for the StructuredText field. | ||
module StructuredTextFilter | ||
def structured_text(field, space = nil) | ||
return if field.nil? | ||
|
||
StructuredTextRenderer::Renderer.new(mappings_for(space)).render(field) | ||
end | ||
|
||
private | ||
|
||
def mappings_for(space) | ||
mappings = {} | ||
config_for(space).fetch('structured_text_mappings', {}).each do |k, v| | ||
mappings[k.to_s] = Module.const_get(v) | ||
end | ||
|
||
mappings | ||
end | ||
|
||
def config_for(space) | ||
config = @context.registers[:site].config['contentful']['spaces'] | ||
|
||
# Spaces is a list of hashes indexed by space alias | ||
return config.first.first[1] if space.nil? # Return the first available configuration | ||
config.find { |sc| sc.key?(space) }[space] | ||
end | ||
end | ||
end | ||
end | ||
|
||
Liquid::Template.register_filter(Jekyll::Contentful::StructuredTextFilter) |
Oops, something went wrong.