Compare commits

...

32 Commits

Author SHA1 Message Date
b50df4e6de add categories 2022-06-09 23:19:08 -04:00
2f8ba8513e rollback 2022-06-09 22:32:24 -04:00
ca1dac246b rollback 2022-06-09 22:31:52 -04:00
ef5b6a7c16 added authentication 2022-06-09 22:30:05 -04:00
d11b959a23 rollback 2022-06-09 22:16:48 -04:00
b4b10d0c7b rollback 2022-06-09 22:15:40 -04:00
d4916735ce rollback 2022-06-09 22:14:54 -04:00
369c51f543 rollback 2022-06-09 22:13:56 -04:00
a5f4af95d5 Update 'lib/jekyll/strapi/generator.rb' 2022-06-09 22:04:08 -04:00
1d266102c7 Update 'lib/jekyll/strapi/generator.rb' 2022-06-09 21:56:15 -04:00
7ceee20c23 Update 'lib/jekyll/strapi/version.rb' 2022-06-09 21:12:27 -04:00
2b36dbcec7 Update 'README.md' 2022-06-09 19:10:08 -04:00
d006a57f09 added authentication 2022-06-09 19:08:53 -04:00
6bd9a7c422 added authentication 2022-06-09 19:08:10 -04:00
1b26c0d7e0 add authentication 2022-06-09 19:06:56 -04:00
dfd03ccfa8 Add 'lib/jekyll/strapi/strapihttp.rb' 2022-06-09 19:05:23 -04:00
b2e79f0557 add auth token for Strapi 2022-06-09 19:03:47 -04:00
8a48d1d910 Update 'lib/jekyll/strapi/site.rb' 2022-06-09 18:47:01 -04:00
8c4a56c1de Update 'lib/jekyll/strapi/generator.rb' 2022-06-09 18:45:37 -04:00
ea40459421 add strapi v4 jekyll 2022-06-09 18:44:56 -04:00
84094c1d83 add images 2022-06-09 18:42:49 -04:00
e11f7d2e4c Update 'README.md' 2022-06-09 18:41:33 -04:00
92d3a5d341 Update 'LICENSE' 2022-06-09 18:37:32 -04:00
f83cd1082a Update 'lib/jekyll/strapi/version.rb' 2022-06-09 18:36:00 -04:00
479ac66a8f add images.rb filter 2022-06-09 18:27:50 -04:00
b7fad54e44 add images from remote Strapi 2022-06-09 18:23:29 -04:00
Charles
1aa4c8642e
Update generator.rb 2022-06-01 01:18:39 -04:00
Charles
12b189ccab
add more placeholders + update :slug for strapiv4 2022-06-01 00:46:31 -04:00
Charles
dc44d2ada4
write :data to permalink when output is true 2022-06-01 00:42:16 -04:00
Charles
91f4f855b5
Update collection.rb 2022-05-27 16:23:50 -04:00
Charles
65760193c2
populate all data from collection
without ```?populate=*``` I didn't get any image data.
2022-05-25 01:21:20 -04:00
oDinZu
ac911ed3f0 make jekyll-strapi plugin work with strapi-v4 2022-05-25 00:00:00 -04:00
9 changed files with 91 additions and 26 deletions

View File

View File

@ -1,4 +1,11 @@
# jekyll-strapi
# jekyll-strapi reboot
## Features
* Support for Strapi 4
* Authentication
* Permalinks
* Caching and collecting assets from Strapi
## Install
@ -24,37 +31,71 @@ strapi:
# Collections, key is used to access in the strapi.collections
# template variable
collections:
# Example for a "articles" collection
articles:
# Example for a "Photo" collection
photos:
# Collection name (optional)
type: article
# type: photos
# Permalink used to generate the output files (eg. /articles/:id).
permalink: /articles/:id/
permalink: /photos/:id/
# Layout file for this collection
layout: strapi_article.html
layout: photo.html
# Generate output files or not (default: false)
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
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.
### Using Collections
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:
To list all documents of the collection ```_layouts/home.html```:
```
{% for post in strapi.collections.articles %}
<article>
<header>
{{ post.title }}
</header>
<div class="body">
{{ post.content }}
</div>
</article>
{% endfor %}
---
layout: default
---
<div class="home">
<h1 class="page-heading">Photos</h1>
{%- if strapi.collections.photos.size > 0 -%}
<ul>
{%- for photo in strapi.collections.photos -%}
<li>
<a href="{{ photo.url }}">Title: {{ photo.title }}</a>
</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>
```

View File

@ -16,7 +16,9 @@ Gem::Specification.new do |spec|
A Jekyll plugin for retrieving content from a Strapi API
DESC
# spec.add_runtime_dependency("down", "~> 5.0")
spec.add_runtime_dependency("jekyll", ">= 4")
spec.add_runtime_dependency("http", "~> 3.2")
spec.add_runtime_dependency("json", "~> 2.1")
end

View File

@ -1,6 +1,8 @@
require 'jekyll/strapi/strapihttp'
require 'jekyll/strapi/collection'
require 'jekyll/strapi/drops'
require 'jekyll/strapi/generator'
require 'jekyll/strapi/hooks'
require 'jekyll/strapi/site'
require 'jekyll/strapi/version'
# require 'jekyll/strapi/strapiimagefilter'

View File

@ -23,7 +23,9 @@ module Jekyll
uri = URI("#{@site.endpoint}#{path}")
Jekyll.logger.info "Jekyll Strapi:", "Fetching entries from #{uri}"
# Get entries
response = Net::HTTP.get_response(uri)
# response = Net::HTTP.get_response(uri)
# add auth token
response = strapi_request(uri)
# Check response code
if response.code == "200"
result = JSON.parse(response.body, object_class: OpenStruct)
@ -34,14 +36,14 @@ module Jekyll
end
# Add necessary properties
result.each do |document|
result.data.each do |document|
document.type = collection_name
document.collection = collection_name
document.id ||= document._id
document.url = @site.strapi_link_resolver(collection_name, document)
end
result.each {|x| yield(x)}
result.data.each {|x| yield(x)}
end
end
end

View File

@ -38,7 +38,7 @@ module Jekyll
end
def url_placeholders
requiredValues = @document.to_h.select {|k, v|
requiredValues = @document.attributes.to_h.select {|k, v|
v.class == String and @collection.config['permalink'].include? k.to_s
}

View File

@ -30,8 +30,13 @@ module Jekyll
:placeholders => {
:id => document.id.to_s,
:uid => document.uid,
:slug => document.slug,
:type => document.type
:slug => document.attributes.slug,
:type => document.type,
:date => document.attributes.date,
:title => document.attributes.title,
:category => document.attributes.category
# look inside jekyll _data folder
#:title => document.data,
}
)
@ -42,4 +47,4 @@ module Jekyll
strapi_collections[collection_name]
end
end
end
end

View File

@ -0,0 +1,13 @@
##
# 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

View File

@ -1,5 +1,5 @@
module Jekyll
module Strapi
VERSION = "0.1.2"
VERSION = "0.1.3"
end
end