Compare commits
2 Commits
strapi-v4-
...
master
Author | SHA1 | Date | |
---|---|---|---|
ed4f12a442 | |||
bb7dd71f32 |
75
README.md
75
README.md
@ -1,11 +1,4 @@
|
|||||||
# jekyll-strapi reboot
|
# jekyll-strapi
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
* Support for Strapi 4
|
|
||||||
* Authentication
|
|
||||||
* Permalinks
|
|
||||||
* Caching and collecting assets from Strapi
|
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
@ -31,30 +24,18 @@ strapi:
|
|||||||
# Collections, key is used to access in the strapi.collections
|
# Collections, key is used to access in the strapi.collections
|
||||||
# template variable
|
# template variable
|
||||||
collections:
|
collections:
|
||||||
# Example for a "Photo" collection
|
# Example for a "articles" collection
|
||||||
photos:
|
articles:
|
||||||
# Collection name (optional)
|
# Collection name (optional)
|
||||||
# type: photos
|
type: article
|
||||||
# Permalink used to generate the output files (eg. /articles/:id).
|
# Permalink used to generate the output files (eg. /articles/:id).
|
||||||
permalink: /photos/:id/
|
permalink: /articles/:id/
|
||||||
# Layout file for this collection
|
# Layout file for this collection
|
||||||
layout: photo.html
|
layout: strapi_article.html
|
||||||
# Generate output files or not (default: false)
|
# Generate output files or not (default: false)
|
||||||
output: true
|
output: true
|
||||||
```
|
```
|
||||||
|
|
||||||
This works for the following collection *Photo* in Strapi:
|
|
||||||
|
|
||||||
| Name | Type |
|
|
||||||
| ------- | ----- |
|
|
||||||
| Title | Text |
|
|
||||||
| Image | Media |
|
|
||||||
| Comment | Text |
|
|
||||||
|
|
||||||
### Authentication
|
|
||||||
|
|
||||||
To access non Public collections (and by default all Strapi collections are non Public) you must to generate a token inside your strapi instance and set it as enviromental variable `STRAPI_TOKEN`.
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
This plugin provides the `strapi` template variable. This template provides access to the collections defined in the configuration.
|
This plugin provides the `strapi` template variable. This template provides access to the collections defined in the configuration.
|
||||||
@ -63,39 +44,17 @@ This plugin provides the `strapi` template variable. This template provides acce
|
|||||||
|
|
||||||
Collections are accessed by their name in `strapi.collections`. The `articles` collections is available at `strapi.collections.articles`.
|
Collections are accessed by their name in `strapi.collections`. The `articles` collections is available at `strapi.collections.articles`.
|
||||||
|
|
||||||
To list all documents of the collection ```_layouts/home.html```:
|
To list all documents of the collection:
|
||||||
|
|
||||||
```
|
```
|
||||||
---
|
{% for post in strapi.collections.articles %}
|
||||||
layout: default
|
<article>
|
||||||
---
|
<header>
|
||||||
<div class="home">
|
{{ post.title }}
|
||||||
<h1 class="page-heading">Photos</h1>
|
</header>
|
||||||
{%- if strapi.collections.photos.size > 0 -%}
|
<div class="body">
|
||||||
<ul>
|
{{ post.content }}
|
||||||
{%- for photo in strapi.collections.photos -%}
|
</div>
|
||||||
<li>
|
</article>
|
||||||
<a href="{{ photo.url }}">Title: {{ photo.title }}</a>
|
{% endfor %}
|
||||||
</li>
|
|
||||||
{%- endfor -%}
|
|
||||||
</ul>
|
|
||||||
{%- endif -%}
|
|
||||||
</div>
|
|
||||||
```
|
|
||||||
|
|
||||||
### Attributes
|
|
||||||
|
|
||||||
All object's data you can access through ``` {{ page.document.strapi_attributes }}```. This plugin also introduces new filter asset_url which perform downloading the asset into the assets folder and provides correct url. Thanks for this you have copies of your assets locally without extra dependency on Strapi ```_layouts/photo.html```:
|
|
||||||
|
|
||||||
```
|
|
||||||
---
|
|
||||||
layout: default
|
|
||||||
---
|
|
||||||
|
|
||||||
<div class="home">
|
|
||||||
<h1 class="page-heading">{{ page.document.title }}</h1>
|
|
||||||
<h2>{{ page.document.strapi_attributes.Title }}</h2>
|
|
||||||
<p>{{ page.document.strapi_attributes.Comment }}</p>
|
|
||||||
<img src="{{ page.document.strapi_attributes.Image.data.attributes.formats.thumbnail| asset_url }}"/>
|
|
||||||
</div>
|
|
||||||
```
|
```
|
||||||
|
@ -16,9 +16,7 @@ Gem::Specification.new do |spec|
|
|||||||
A Jekyll plugin for retrieving content from a Strapi API
|
A Jekyll plugin for retrieving content from a Strapi API
|
||||||
DESC
|
DESC
|
||||||
|
|
||||||
# spec.add_runtime_dependency("down", "~> 5.0")
|
|
||||||
spec.add_runtime_dependency("jekyll", ">= 4")
|
spec.add_runtime_dependency("jekyll", ">= 4")
|
||||||
spec.add_runtime_dependency("http", "~> 3.2")
|
spec.add_runtime_dependency("http", "~> 3.2")
|
||||||
spec.add_runtime_dependency("json", "~> 2.1")
|
spec.add_runtime_dependency("json", "~> 2.1")
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
require 'jekyll/strapi/strapihttp'
|
|
||||||
require 'jekyll/strapi/collection'
|
require 'jekyll/strapi/collection'
|
||||||
require 'jekyll/strapi/drops'
|
require 'jekyll/strapi/drops'
|
||||||
require 'jekyll/strapi/generator'
|
require 'jekyll/strapi/generator'
|
||||||
require 'jekyll/strapi/hooks'
|
require 'jekyll/strapi/hooks'
|
||||||
require 'jekyll/strapi/site'
|
require 'jekyll/strapi/site'
|
||||||
require 'jekyll/strapi/version'
|
require 'jekyll/strapi/version'
|
||||||
# require 'jekyll/strapi/strapiimagefilter'
|
|
||||||
|
@ -23,9 +23,7 @@ module Jekyll
|
|||||||
uri = URI("#{@site.endpoint}#{path}")
|
uri = URI("#{@site.endpoint}#{path}")
|
||||||
Jekyll.logger.info "Jekyll Strapi:", "Fetching entries from #{uri}"
|
Jekyll.logger.info "Jekyll Strapi:", "Fetching entries from #{uri}"
|
||||||
# Get entries
|
# Get entries
|
||||||
# response = Net::HTTP.get_response(uri)
|
response = Net::HTTP.get_response(uri)
|
||||||
# add auth token
|
|
||||||
response = strapi_request(uri)
|
|
||||||
# Check response code
|
# Check response code
|
||||||
if response.code == "200"
|
if response.code == "200"
|
||||||
result = JSON.parse(response.body, object_class: OpenStruct)
|
result = JSON.parse(response.body, object_class: OpenStruct)
|
||||||
@ -36,14 +34,14 @@ module Jekyll
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Add necessary properties
|
# Add necessary properties
|
||||||
result.data.each do |document|
|
result.each do |document|
|
||||||
document.type = collection_name
|
document.type = collection_name
|
||||||
document.collection = collection_name
|
document.collection = collection_name
|
||||||
document.id ||= document._id
|
document.id ||= document._id
|
||||||
document.url = @site.strapi_link_resolver(collection_name, document)
|
document.url = @site.strapi_link_resolver(collection_name, document)
|
||||||
end
|
end
|
||||||
|
|
||||||
result.data.each {|x| yield(x)}
|
result.each {|x| yield(x)}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -38,7 +38,7 @@ module Jekyll
|
|||||||
end
|
end
|
||||||
|
|
||||||
def url_placeholders
|
def url_placeholders
|
||||||
requiredValues = @document.attributes.to_h.select {|k, v|
|
requiredValues = @document.to_h.select {|k, v|
|
||||||
v.class == String and @collection.config['permalink'].include? k.to_s
|
v.class == String and @collection.config['permalink'].include? k.to_s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,13 +30,8 @@ module Jekyll
|
|||||||
:placeholders => {
|
:placeholders => {
|
||||||
:id => document.id.to_s,
|
:id => document.id.to_s,
|
||||||
:uid => document.uid,
|
:uid => document.uid,
|
||||||
:slug => document.attributes.slug,
|
:slug => document.slug,
|
||||||
:type => document.type,
|
:type => document.type
|
||||||
:date => document.attributes.date,
|
|
||||||
:title => document.attributes.title,
|
|
||||||
:category => document.attributes.category
|
|
||||||
# look inside jekyll _data folder
|
|
||||||
#:title => document.data,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
##
|
|
||||||
# This is a helper method to authenticate during getting data from Strapi instance.
|
|
||||||
|
|
||||||
def strapi_request(url)
|
|
||||||
strapi_token = ENV['STRAPI_TOKEN']
|
|
||||||
uri = URI(url)
|
|
||||||
req = Net::HTTP::Get.new(uri)
|
|
||||||
req['Authorization'] = "Bearer #{strapi_token}"
|
|
||||||
headers = {
|
|
||||||
'Authorization'=>"Bearer #{strapi_token}"
|
|
||||||
}
|
|
||||||
Net::HTTP.get_response(uri, headers)
|
|
||||||
end
|
|
@ -1,5 +1,5 @@
|
|||||||
module Jekyll
|
module Jekyll
|
||||||
module Strapi
|
module Strapi
|
||||||
VERSION = "0.1.3"
|
VERSION = "0.2.0"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user