osuny-owl 1.1.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/npm-publish.yml +21 -0
- package/{index.js → index_old.js} +31 -3
- package/package.json +5 -8
- package/readme.md +2 -4
- package/src/OsunyOwl.js +63 -0
- package/src/api/client.js +28 -0
- package/src/api/endpoint.js +4 -0
- package/src/builders/blocks/chapter.js +32 -0
- package/src/builders/blocks/datatable.js +17 -0
- package/src/builders/blocks/image.js +21 -0
- package/src/builders/blocks/index.js +5 -0
- package/src/builders/blocks/title.js +28 -0
- package/src/builders/blocks/video.js +18 -0
- package/src/builders/content.js +118 -0
- package/src/builders/index.js +23 -0
- package/src/index.js +2 -0
- package/src/ressources/posts.js +13 -0
- package/src/utils/slug.js +9 -0
- package/osuny_utility.js +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# This workflow will publish a package to npm when a release is created
|
|
2
|
+
|
|
3
|
+
name: Node.js Package
|
|
4
|
+
|
|
5
|
+
on:
|
|
6
|
+
release:
|
|
7
|
+
types: [created]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
publish-npm:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: actions/setup-node@v4
|
|
15
|
+
with:
|
|
16
|
+
node-version: 20
|
|
17
|
+
registry-url: https://registry.npmjs.org/
|
|
18
|
+
- run: npm ci
|
|
19
|
+
- run: npm publish
|
|
20
|
+
env:
|
|
21
|
+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
|
@@ -303,22 +303,23 @@ export class OsunyUtility{
|
|
|
303
303
|
* @param {string} title (Required) Title of the article / post
|
|
304
304
|
* @param {string} migration_identifier (Required) A unique identifier to catch its migration in the logs
|
|
305
305
|
* @param {Array} blocks (Required) Array of the different Communication::Blocks composing the post
|
|
306
|
+
* @param {String} locale (Optional) Set the locale of the post created. Set to "fr" by default
|
|
306
307
|
* @param {Array} category_ids (Optional) Array of strings representing the category or all the categories attached to this post. Empty Array by default
|
|
307
308
|
* @param {Date} crea_dt (Optional) Date of the post. Undefined by default
|
|
308
309
|
* @param {boolean} full_width (Optional) Indicates if the article should take all the theme width. False by default
|
|
309
310
|
* @param {string} summary (Optional) A short text that summerize the post. Empty string by default
|
|
310
311
|
* @returns Osuny's Communication::Post object.
|
|
311
312
|
*/
|
|
312
|
-
static createPost(title, migration_identifier, blocks, category_ids = [], crea_dt=undefined, full_width=false, summary=""){
|
|
313
|
+
static createPost(title, migration_identifier, blocks, locale = "fr", category_ids = [], crea_dt=undefined, full_width=false, summary=""){
|
|
313
314
|
return {
|
|
314
315
|
"id": undefined,
|
|
315
316
|
"migration_identifier": migration_identifier,
|
|
316
317
|
"full_width": full_width,
|
|
317
318
|
"category_ids": category_ids,
|
|
318
319
|
"localizations": {
|
|
319
|
-
|
|
320
|
+
[locale]: {
|
|
320
321
|
"id": undefined,
|
|
321
|
-
"migration_identifier": migration_identifier +
|
|
322
|
+
"migration_identifier": migration_identifier + `_${locale}`,
|
|
322
323
|
"title": title,
|
|
323
324
|
"featured_image": undefined,
|
|
324
325
|
"pinned": false,
|
|
@@ -334,6 +335,33 @@ export class OsunyUtility{
|
|
|
334
335
|
}
|
|
335
336
|
}
|
|
336
337
|
|
|
338
|
+
static createProject(title, migration_identifier, year, blocks, locale="fr", category_ids = [], full_width=true, crea_dt=undefined, summary=""){
|
|
339
|
+
return {
|
|
340
|
+
"id": undefined,
|
|
341
|
+
"migration_identifier": migration_identifier,
|
|
342
|
+
"full_width": full_width,
|
|
343
|
+
"year": year,
|
|
344
|
+
"category_ids": category_ids,
|
|
345
|
+
"localizations": {
|
|
346
|
+
[locale]: {
|
|
347
|
+
"id": undefined,
|
|
348
|
+
"migration_identifier": migration_identifier + `_${locale}`,
|
|
349
|
+
"title": title,
|
|
350
|
+
"featured_image": undefined,
|
|
351
|
+
"pinned": false,
|
|
352
|
+
"published": true,
|
|
353
|
+
"published_at": crea_dt,
|
|
354
|
+
"slug": this.slugify(title),
|
|
355
|
+
"summary": summary,
|
|
356
|
+
"blocks": blocks,
|
|
357
|
+
"created_at": crea_dt
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
|
|
337
365
|
/**
|
|
338
366
|
*
|
|
339
367
|
* @param {...Object} osunyBlocks Osuny's Communication::Block in JSON.
|
package/package.json
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "osuny-owl",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Osuny Owl is an object that can go talk to the Osuny API, to create post or other osuny components from a large amount of data",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"osuny",
|
|
7
|
-
"api"
|
|
8
|
-
],
|
|
5
|
+
"keywords": ["osuny", "api"],
|
|
9
6
|
"license": "GPL-3.0",
|
|
10
7
|
"author": "Sacha André",
|
|
11
8
|
"type": "module",
|
|
12
|
-
"main": "index.js",
|
|
9
|
+
"main": "src/index.js",
|
|
13
10
|
"scripts": {
|
|
14
|
-
"test": "echo \"
|
|
11
|
+
"test": "echo \"No test for this package\" && exit 0"
|
|
15
12
|
},
|
|
16
13
|
"dependencies": {
|
|
17
14
|
"dotenv": "^16.5.0",
|
|
18
15
|
"node-fetch": "^3.3.2"
|
|
19
16
|
}
|
|
20
|
-
}
|
|
17
|
+
}
|
package/readme.md
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
Osuny Owl is a little package that adds a cute owl who can help you talk with an Osuny API.
|
|
4
4
|
Still under construction, it's main use is for the creation of large sums of data, or for external apps that want to create posts in a static website. (With Peuplier for exemple)
|
|
5
5
|
|
|
6
|
-
>[!NOTE]
|
|
7
|
-
> This package is for the moment usable only for websites localized in french.
|
|
8
6
|
|
|
9
7
|
## Adopt an owl
|
|
10
8
|
|
|
@@ -20,7 +18,7 @@ Here, `website_id` is the unique identifier of one of your websites and `api_url
|
|
|
20
18
|
## The OsunyUtility
|
|
21
19
|
|
|
22
20
|
> [!NOTE]
|
|
23
|
-
> The Utility is for the moment very limited.
|
|
21
|
+
> The Utility is for the moment very limited. All the Blocks are not supported
|
|
24
22
|
|
|
25
23
|
To use it in your app, you can import it like this
|
|
26
24
|
|
|
@@ -30,4 +28,4 @@ import { OsunyUtility } from 'osuny-owl';
|
|
|
30
28
|
let chapterOne = OsunyUtility.createChapter(...)
|
|
31
29
|
let datatableOne = OsunyUtility.createDatable(...)
|
|
32
30
|
let postOne = OsunyUtility.createPost(...)
|
|
33
|
-
```
|
|
31
|
+
```
|
package/src/OsunyOwl.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import { apiPost } from './api/client.js';
|
|
3
|
+
|
|
4
|
+
export class OsunyOwl {
|
|
5
|
+
constructor(website_id, api_url) {
|
|
6
|
+
this.website_id = website_id;
|
|
7
|
+
this.category_ids = [];
|
|
8
|
+
this.api_key_defined = process.env.OSUNY_API_KEY ? true : false;
|
|
9
|
+
this.api_url = api_url;
|
|
10
|
+
this.last_media = undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
set website_id(website_id) {
|
|
14
|
+
this._website_id = website_id;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
set category_ids(category_ids) {
|
|
18
|
+
this._category_ids = category_ids;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
checkApiKey() {
|
|
22
|
+
this.api_key_defined = process.env.OSUNY_API_KEY ? true : false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get website_id() {
|
|
26
|
+
return this._website_id;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get category_ids() {
|
|
30
|
+
return this._category_ids;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
addCategory_id(category_id) {
|
|
34
|
+
this.category_ids.push(category_id);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
removeCategory_id(category_id) {
|
|
38
|
+
if (this.category_ids.includes(category_id)) {
|
|
39
|
+
this.category_ids = this.category_ids.filter(e => e !== category_id);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async postToOsuny(post) {
|
|
44
|
+
if (this.api_key_defined) {
|
|
45
|
+
const url = this.api_url + "/communication/websites/" + this.website_id + "/posts";
|
|
46
|
+
await apiPost(url, post, process.env.OSUNY_API_KEY, false);
|
|
47
|
+
return true;
|
|
48
|
+
} else {
|
|
49
|
+
throw new Error("No API Key Defined");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async importImage(img_bdy) {
|
|
54
|
+
if (this.api_key_defined) {
|
|
55
|
+
const url = this.api_url + "/communication/medias";
|
|
56
|
+
let dataR = await apiPost(url, img_bdy, process.env.OSUNY_API_KEY, true);
|
|
57
|
+
this.last_media = dataR.original_blob;
|
|
58
|
+
return true;
|
|
59
|
+
} else {
|
|
60
|
+
throw new Error("No API Key Defined");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
|
|
3
|
+
export async function apiPost(url, data, apiKey, isFormData = false) {
|
|
4
|
+
const headers = {
|
|
5
|
+
'X-Osuny-Token': apiKey
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
if (!isFormData) {
|
|
9
|
+
headers['Content-Type'] = 'application/json';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const response = await fetch(url, {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
headers,
|
|
16
|
+
body: isFormData ? data : JSON.stringify(data)
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
throw new Error(`Response status: ${response.status}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return await response.json();
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error(error.message);
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function createChapter(text, migration_identifier, position, title = "", layout = 1) {
|
|
2
|
+
let layout_text;
|
|
3
|
+
|
|
4
|
+
switch (layout) {
|
|
5
|
+
case 1:
|
|
6
|
+
layout_text = "no_background";
|
|
7
|
+
break;
|
|
8
|
+
case 2:
|
|
9
|
+
layout_text = "alt_background";
|
|
10
|
+
break;
|
|
11
|
+
case 3:
|
|
12
|
+
layout_text = "accent_background";
|
|
13
|
+
break;
|
|
14
|
+
default:
|
|
15
|
+
layout_text = "no_background";
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
"id": null,
|
|
21
|
+
"migration_identifier": migration_identifier,
|
|
22
|
+
"template_kind": "chapter",
|
|
23
|
+
"title": title,
|
|
24
|
+
"position": position,
|
|
25
|
+
"published": true,
|
|
26
|
+
"html_class": null,
|
|
27
|
+
"data": {
|
|
28
|
+
"layout": layout_text,
|
|
29
|
+
"text": text,
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function createDatatable(table_data, table_headers = [], migration_identifier, position, title = "", alphabetical = false, caption = "") {
|
|
2
|
+
return {
|
|
3
|
+
"id": null,
|
|
4
|
+
"migration_identifier": migration_identifier,
|
|
5
|
+
"template_kind": "datatable",
|
|
6
|
+
"title": title,
|
|
7
|
+
"position": position,
|
|
8
|
+
"published": true,
|
|
9
|
+
"html_class": null,
|
|
10
|
+
"data": {
|
|
11
|
+
"columns": table_headers,
|
|
12
|
+
"elements": table_data,
|
|
13
|
+
"alphabetical": alphabetical,
|
|
14
|
+
"caption": caption
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function createImage(img_id, img_filename, img_signedid, migration_identifier, position, alt = "", credit = "", text = "", title = "") {
|
|
2
|
+
return {
|
|
3
|
+
"id": null,
|
|
4
|
+
"migration_identifier": migration_identifier,
|
|
5
|
+
"template_kind": "image",
|
|
6
|
+
"title": title,
|
|
7
|
+
"position": position,
|
|
8
|
+
"published": "true",
|
|
9
|
+
"html_class": null,
|
|
10
|
+
"data": {
|
|
11
|
+
"image": {
|
|
12
|
+
"id": img_id,
|
|
13
|
+
"filename": img_filename,
|
|
14
|
+
"signed_id": img_signedid
|
|
15
|
+
},
|
|
16
|
+
"alt": alt,
|
|
17
|
+
"credit": credit,
|
|
18
|
+
"text": text
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function createTitle(title, migration_identifier, position, layout = 1) {
|
|
2
|
+
let layout_title;
|
|
3
|
+
|
|
4
|
+
switch (layout) {
|
|
5
|
+
case 1:
|
|
6
|
+
layout_title = "classic";
|
|
7
|
+
break;
|
|
8
|
+
case 2:
|
|
9
|
+
layout_title = "collapsed";
|
|
10
|
+
break;
|
|
11
|
+
default:
|
|
12
|
+
layout_title = "classic";
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
"id": null,
|
|
18
|
+
"migration_identifier": migration_identifier,
|
|
19
|
+
"template_kind": "title",
|
|
20
|
+
"title": title,
|
|
21
|
+
"position": position,
|
|
22
|
+
"published": true,
|
|
23
|
+
"html_class": null,
|
|
24
|
+
"data": {
|
|
25
|
+
"layout": layout_title
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function createVideo(video_url, migration_identifier, position, video_title = "", video_desc = "", video_transc = "", title = "") {
|
|
2
|
+
return {
|
|
3
|
+
"id": null,
|
|
4
|
+
"migration_identifier": migration_identifier,
|
|
5
|
+
"template_kind": "video",
|
|
6
|
+
"title": title,
|
|
7
|
+
"position": position,
|
|
8
|
+
"published": "true",
|
|
9
|
+
"html_class": null,
|
|
10
|
+
"data": {
|
|
11
|
+
"layout": "player",
|
|
12
|
+
"description": video_desc,
|
|
13
|
+
"url": video_url,
|
|
14
|
+
"video_title": video_title,
|
|
15
|
+
"transcription": video_transc
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { slugify } from '../utils/slug.js';
|
|
2
|
+
|
|
3
|
+
export function createPost(title, migration_identifier, blocks, locale = "fr", category_ids = [], crea_dt = undefined, full_width = false, summary = "") {
|
|
4
|
+
return {
|
|
5
|
+
"id": undefined,
|
|
6
|
+
"migration_identifier": migration_identifier,
|
|
7
|
+
"full_width": full_width,
|
|
8
|
+
"category_ids": category_ids,
|
|
9
|
+
"localizations": {
|
|
10
|
+
[locale]: {
|
|
11
|
+
"id": undefined,
|
|
12
|
+
"migration_identifier": migration_identifier + `_${locale}`,
|
|
13
|
+
"title": title,
|
|
14
|
+
"featured_image": undefined,
|
|
15
|
+
"pinned": false,
|
|
16
|
+
"published": true,
|
|
17
|
+
"published_at": crea_dt,
|
|
18
|
+
"slug": slugify(title),
|
|
19
|
+
"summary": summary,
|
|
20
|
+
"blocks": blocks,
|
|
21
|
+
"created_at": crea_dt
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function createProject(title, migration_identifier, year, blocks, locale = "fr", category_ids = [], full_width = true, crea_dt = undefined, summary = "") {
|
|
28
|
+
return {
|
|
29
|
+
"id": undefined,
|
|
30
|
+
"migration_identifier": migration_identifier,
|
|
31
|
+
"full_width": full_width,
|
|
32
|
+
"year": year,
|
|
33
|
+
"category_ids": category_ids,
|
|
34
|
+
"localizations": {
|
|
35
|
+
[locale]: {
|
|
36
|
+
"id": undefined,
|
|
37
|
+
"migration_identifier": migration_identifier + `_${locale}`,
|
|
38
|
+
"title": title,
|
|
39
|
+
"featured_image": undefined,
|
|
40
|
+
"pinned": false,
|
|
41
|
+
"published": true,
|
|
42
|
+
"published_at": crea_dt,
|
|
43
|
+
"slug": slugify(title),
|
|
44
|
+
"summary": summary,
|
|
45
|
+
"blocks": blocks,
|
|
46
|
+
"created_at": crea_dt
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Ajoute une localisation à un post existant
|
|
54
|
+
*
|
|
55
|
+
* @param {Object} post - Le post existant (créé avec createPost)
|
|
56
|
+
* @param {string} locale - Code de la locale (ex: "en", "es", "de")
|
|
57
|
+
* @param {string} title - Titre dans la nouvelle locale
|
|
58
|
+
* @param {Array} blocks - Blocs dans la nouvelle locale
|
|
59
|
+
* @param {string} summary - Résumé dans la nouvelle locale (optionnel)
|
|
60
|
+
* @param {Date} crea_dt - Date de création (optionnel)
|
|
61
|
+
* @returns {Object} Le post modifié avec la nouvelle locale
|
|
62
|
+
*/
|
|
63
|
+
export function addLocaleToPost(post, locale, title, blocks, summary = "", crea_dt = undefined) {
|
|
64
|
+
// Ajouter la nouvelle locale dans l'objet localizations
|
|
65
|
+
post.localizations[locale] = {
|
|
66
|
+
"id": undefined,
|
|
67
|
+
"migration_identifier": post.migration_identifier + `_${locale}`,
|
|
68
|
+
"title": title,
|
|
69
|
+
"featured_image": undefined,
|
|
70
|
+
"pinned": false,
|
|
71
|
+
"published": true,
|
|
72
|
+
"published_at": crea_dt,
|
|
73
|
+
"slug": slugify(title),
|
|
74
|
+
"summary": summary,
|
|
75
|
+
"blocks": blocks,
|
|
76
|
+
"created_at": crea_dt
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return post;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Ajoute une localisation à un projet existant
|
|
84
|
+
*
|
|
85
|
+
* @param {Object} project - Le projet existant (créé avec createProject)
|
|
86
|
+
* @param {string} locale - Code de la locale (ex: "en", "es", "de")
|
|
87
|
+
* @param {string} title - Titre dans la nouvelle locale
|
|
88
|
+
* @param {Array} blocks - Blocs dans la nouvelle locale
|
|
89
|
+
* @param {string} summary - Résumé dans la nouvelle locale (optionnel)
|
|
90
|
+
* @param {Date} crea_dt - Date de création (optionnel)
|
|
91
|
+
* @returns {Object} Le projet modifié avec la nouvelle locale
|
|
92
|
+
*/
|
|
93
|
+
export function addLocaleToProject(project, locale, title, blocks, summary = "", crea_dt = undefined) {
|
|
94
|
+
// Ajouter la nouvelle locale dans l'objet localizations
|
|
95
|
+
project.localizations[locale] = {
|
|
96
|
+
"id": undefined,
|
|
97
|
+
"migration_identifier": project.migration_identifier + `_${locale}`,
|
|
98
|
+
"title": title,
|
|
99
|
+
"featured_image": undefined,
|
|
100
|
+
"pinned": false,
|
|
101
|
+
"published": true,
|
|
102
|
+
"published_at": crea_dt,
|
|
103
|
+
"slug": slugify(title),
|
|
104
|
+
"summary": summary,
|
|
105
|
+
"blocks": blocks,
|
|
106
|
+
"created_at": crea_dt
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
return project;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function composePost(...osunyBlocks) {
|
|
113
|
+
let blocksArray = [];
|
|
114
|
+
osunyBlocks.forEach((el) => {
|
|
115
|
+
blocksArray.push(el);
|
|
116
|
+
});
|
|
117
|
+
return blocksArray;
|
|
118
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as blocks from './blocks/index.js';
|
|
2
|
+
import {
|
|
3
|
+
createPost,
|
|
4
|
+
createProject,
|
|
5
|
+
composePost,
|
|
6
|
+
addLocaleToPost,
|
|
7
|
+
addLocaleToProject
|
|
8
|
+
} from './content.js';
|
|
9
|
+
import { slugify } from '../utils/slug.js';
|
|
10
|
+
|
|
11
|
+
export class OsunyUtility {
|
|
12
|
+
static createTitle = blocks.createTitle;
|
|
13
|
+
static createChapter = blocks.createChapter;
|
|
14
|
+
static createDatatable = blocks.createDatatable;
|
|
15
|
+
static createVideo = blocks.createVideo;
|
|
16
|
+
static createImage = blocks.createImage;
|
|
17
|
+
static createPost = createPost;
|
|
18
|
+
static createProject = createProject;
|
|
19
|
+
static composePost = composePost;
|
|
20
|
+
static addLocaleToPost = addLocaleToPost;
|
|
21
|
+
static addLocaleToProject = addLocaleToProject;
|
|
22
|
+
static slugify = slugify;
|
|
23
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { endpoints } from '../api/endpoints.js';
|
|
2
|
+
|
|
3
|
+
export class PostsResource {
|
|
4
|
+
constructor(client, websiteId) {
|
|
5
|
+
this.client = client;
|
|
6
|
+
this.websiteId = websiteId;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async create(post) {
|
|
10
|
+
const endpoint = endpoints.posts(this.websiteId);
|
|
11
|
+
return this.client.post(endpoint, post);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function slugify(str) {
|
|
2
|
+
// Code taken from: https://dev.to/bybydev/how-to-slugify-a-string-in-javascript-4o9n
|
|
3
|
+
str = str.replace(/^\s+|\s+$/g, ''); // trim leading/trailing white space
|
|
4
|
+
str = str.toLowerCase(); // convert string to lowercase
|
|
5
|
+
str = str.replace(/[^a-z0-9 -]/g, '') // remove any non-alphanumeric characters
|
|
6
|
+
.replace(/\s+/g, '-') // replace spaces with hyphens
|
|
7
|
+
.replace(/-+/g, '-'); // remove consecutive hyphens
|
|
8
|
+
return str;
|
|
9
|
+
}
|
package/osuny_utility.js
DELETED
|
File without changes
|