Skip to content

Commit

Permalink
Merge pull request #34 from AstroPlant/dev
Browse files Browse the repository at this point in the history
alpha 0.2.0 deployment
  • Loading branch information
RmnRss authored Oct 9, 2020
2 parents 4e8684b + 4f86c83 commit ab498ee
Show file tree
Hide file tree
Showing 131 changed files with 6,748 additions and 5,046 deletions.
6 changes: 5 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ LICENSE
.vscode

# strapi
api
api

#storybook
.storybook
components/stories
28 changes: 0 additions & 28 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,3 @@ npm run develop
```

When Strapi is installed you should be asked to create a Strapi admin account on your [localhost:1337](localhost:1337).

### Create some content

Before our Strapi app becomes fully operational, wwe need to add some content and configure some part of it.

1. Create a test user

Under the **collection type** menu click **Users**, then create a user with the following information :

```
username: 'Testeroo',
email: '[email protected]',
password: 'Testeroo72',
```

Feel free to fill the rest of the information.

2. Create at least an article

Under the **collection type** menu click **Articles**, then create an article.

> :warning: **Do not forget to add an author to the article and set the article status to published** !
3. Add the correct permissions.

Click on the **Roles & Permissions** tabs, then add the permission following [this file](by following the steps [here](https://astroplant.gitbook.io/community-platform/)).

You should be able to set up the front end by following the steps [here](https://github.com/AstroPlant/community-platform).
35 changes: 18 additions & 17 deletions api/api/article/controllers/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const removeMd = require("remove-markdown");
* Upload a file to strapi using the upload service
* @param {*} url
*/
const uploadFromUrl = async url => {
const uploadFromUrl = async (url) => {
// Downloading
const downloaded = await strapi.config.functions.download(url);

Expand All @@ -26,18 +26,18 @@ const uploadFromUrl = async url => {
* Searching for images in the content.
* @param {*} content
*/
const findImgUrls = content => {
return Array.from(content.matchAll(/!\[(.*?)\]\((.*?)\)/g), m => ({
const findImgUrls = (content) => {
return Array.from(content.matchAll(/!\[(.*?)\]\((.*?)\)/g), (m) => ({
alt: m[1],
url: m[2]
url: m[2],
}));
};

/**
* create a preview based of the article content
* @param {*} content
*/
const createPreview = content => {
const createPreview = (content) => {
const plainText = removeMd(content);

return plainText.substring(0, 136) + "...";
Expand All @@ -48,26 +48,28 @@ module.exports = {
const turndownService = new TurndownService();

const { data } = await axios.get(
"https://www.astroplant.io/wp-json/wp/v2/posts?per_page=1&page=1"
"https://www.astroplant.io/wp-json/wp/v2/posts?per_page=50&page=1"
);

const posts = await Promise.all(
data.map(
post =>
(post) =>
new Promise(async (resolve, reject) => {
const {
title: { rendered: titleRendered },
content: { rendered: contentRendered },
date,
jetpack_featured_media_url
jetpack_featured_media_url,
} = post;

const slug = slugify(titleRendered, {
lower: true
const mdTitle = turndownService.turndown(titleRendered);

const slug = slugify(mdTitle, {
lower: true,
});

const existingArticle = await strapi.query("article").findOne({
slug: slug
slug: slug,
});

if (existingArticle) {
Expand Down Expand Up @@ -113,8 +115,7 @@ module.exports = {

// Creating object
const articleData = {
title: titleRendered,
slug: slug,
title: mdTitle,
cover: coverId,
preview: createPreview(mdContent),
published: true,
Expand All @@ -123,9 +124,9 @@ module.exports = {
content: [
{
__component: "content-type.rich-text",
text: mdContent
}
]
text: mdContent,
},
],
};

try {
Expand All @@ -143,5 +144,5 @@ module.exports = {
);

return posts;
}
},
};
12 changes: 2 additions & 10 deletions api/api/article/models/article.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
"collectionName": "articles",
"info": {
"name": "Article",
"description": "An official piece of news from AstroPlant"
"description": "An official piece of news from AstroPlant."
},
"options": {
"increments": true
},
"attributes": {
"title": {
"type": "string",
"description": "Title of the article.",
"required": true,
"unique": true
},
Expand All @@ -20,7 +19,6 @@
"targetField": "title"
},
"cover": {
"description": "Image Illustrating the article",
"model": "file",
"via": "related",
"allowedTypes": ["images", "videos"],
Expand All @@ -29,19 +27,16 @@
},
"preview": {
"type": "text",
"description": "A short description of what the article is about.",
"required": true,
"maxLength": 140,
"minLength": 1
},
"categories": {
"description": "The categories/topics of the article",
"collection": "category",
"via": "article"
},
"content": {
"type": "dynamiczone",
"description": "Content of the article.",
"components": [
"content-type.file",
"content-type.image",
Expand All @@ -52,18 +47,15 @@
"required": true
},
"author": {
"description": "User who wrote the article.",
"plugin": "users-permissions",
"model": "user"
},
"published": {
"type": "boolean",
"description": "Whether or not the article is published.",
"default": false
},
"published_at": {
"type": "date",
"description": "Date at which the article was published."
"type": "date"
}
}
}
3 changes: 2 additions & 1 deletion api/api/category/models/category.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"kind": "collectionType",
"collectionName": "categories",
"info": {
"name": "category"
"name": "category",
"description": "A category of an article."
},
"options": {
"increments": true,
Expand Down
3 changes: 2 additions & 1 deletion api/api/faq/models/faq.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"kind": "collectionType",
"collectionName": "faqs",
"info": {
"name": "FAQ"
"name": "FAQ",
"description": "Frequently Asked Question."
},
"options": {
"increments": true,
Expand Down
52 changes: 52 additions & 0 deletions api/api/feature/config/routes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"routes": [
{
"method": "GET",
"path": "/features",
"handler": "feature.find",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/features/count",
"handler": "feature.count",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/features/:id",
"handler": "feature.findOne",
"config": {
"policies": []
}
},
{
"method": "POST",
"path": "/features",
"handler": "feature.create",
"config": {
"policies": []
}
},
{
"method": "PUT",
"path": "/features/:id",
"handler": "feature.update",
"config": {
"policies": []
}
},
{
"method": "DELETE",
"path": "/features/:id",
"handler": "feature.delete",
"config": {
"policies": []
}
}
]
}
8 changes: 8 additions & 0 deletions api/api/feature/controllers/feature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

/**
* Read the documentation (https://strapi.io/documentation/v3.x/concepts/controllers.html#core-controllers)
* to customize this controller
*/

module.exports = {};
8 changes: 8 additions & 0 deletions api/api/feature/models/feature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

/**
* Read the documentation (https://strapi.io/documentation/v3.x/concepts/models.html#lifecycle-hooks)
* to customize this model
*/

module.exports = {};
27 changes: 27 additions & 0 deletions api/api/feature/models/feature.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"kind": "collectionType",
"collectionName": "features",
"info": {
"name": "Feature",
"description": "A feature to be added to the roadmap."
},
"options": {
"increments": true,
"timestamps": true
},
"attributes": {
"name": {
"type": "string",
"required": true
},
"stage": {
"type": "enumeration",
"enum": ["under_consideration", "planned", "in_development", "launched"],
"default": "under_consideration"
},
"description": {
"type": "richtext",
"required": true
}
}
}
8 changes: 8 additions & 0 deletions api/api/feature/services/feature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

/**
* Read the documentation (https://strapi.io/documentation/v3.x/concepts/services.html#core-services)
* to customize this service
*/

module.exports = {};
3 changes: 2 additions & 1 deletion api/api/help-section/models/help-section.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"kind": "collectionType",
"collectionName": "help_sections",
"info": {
"name": "HelpSection"
"name": "HelpSection",
"description": "Sections to sort FAQs."
},
"options": {
"increments": true,
Expand Down
18 changes: 10 additions & 8 deletions api/api/library-media/models/library-media.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ async function updateSection(sectionId) {
module.exports = {
lifecycles: {
async afterCreate(result, data) {
updateSection(result.library_section.id);
await updateSection(result.library_section.id);
},
async afterDelete(results, data) {
for (let res of results) {
updateSection(res.library_section.id);
if (results.length > 0) {
for (let res of results) {
await updateSection(res.library_section.id);
}
}
},
async afterUpdate(result, params, data) {
updateSection(result.library_section.id);
await updateSection(result.library_section.id);
},
async beforeCreate(data) {
// Auto creating the slug
if (data.title) {
data.slug = slugify(data.title, {
lower: true
lower: true,
});
}

Expand All @@ -40,7 +42,7 @@ module.exports = {
// Auto updating the slug
if (data.title) {
data.slug = slugify(data.title, {
lower: true
lower: true,
});
}

Expand All @@ -52,6 +54,6 @@ module.exports = {
);
}
}
}
}
},
},
};
Loading

0 comments on commit ab498ee

Please sign in to comment.