Compare commits
5 Commits
af686535e7
...
abaa3b2ae9
Author | SHA1 | Date |
---|---|---|
Arjan Adriaanse | abaa3b2ae9 | |
Kiara Grouwstra | d5b38ea3ed | |
Kiara Grouwstra | d78066b90a | |
Kiara Grouwstra | f3efbcbc63 | |
Kiara Grouwstra | 81c7890e03 |
15
README.md
15
README.md
|
@ -31,17 +31,24 @@ requires setting environment variables, for example:
|
|||
|
||||
```
|
||||
export WINGS_ENDPOINT=https://api.wings.dev
|
||||
export WINGS_PROJECT=amsterdam.bij1.org
|
||||
export WINGS_PROJECT=<PROJECT_ID>
|
||||
export WINGS_APP_KEY=<APP_KEY>
|
||||
```
|
||||
|
||||
These credentials can be generated by adding an App in the Wings admin
|
||||
backend.
|
||||
|
||||
## `yarn migrate`
|
||||
|
||||
Converts all articles and pages that do not exist in WordPress yet and
|
||||
publishes them along with their media, requires setting environment variables, for example:
|
||||
publishes them along with their media, requires setting environment
|
||||
variables, for example:
|
||||
|
||||
```
|
||||
export WP_ENDPOINT=http://localhost:8000/wp-json
|
||||
export WP_USER=<user>
|
||||
export WP_PASSWORD=<pw>
|
||||
export WP_USER=<USERNAME>
|
||||
export WP_PASSWORD=<APPLICATION_PASSWORD>
|
||||
```
|
||||
|
||||
Note that using this API requires a specific application password
|
||||
which can be generated from the user management page.
|
||||
|
|
|
@ -7,7 +7,7 @@ console.log(query);
|
|||
got.post(process.env.WINGS_ENDPOINT || 'https://api.wings.dev', {
|
||||
headers: {
|
||||
"Authorization": "Bearer " + process.env.WINGS_APP_KEY,
|
||||
"x-wings-app-domain": process.env.WINGS_PROJECT
|
||||
"X-Wings-Project": process.env.WINGS_PROJECT
|
||||
},
|
||||
json: {query}
|
||||
}).json().then((data) => {
|
||||
|
|
|
@ -7,6 +7,10 @@ import path from "path";
|
|||
import { renderer, media } from './blocks';
|
||||
import { data } from '../content';
|
||||
|
||||
console.log(`endpoint: ${process.env.WP_ENDPOINT}`);
|
||||
console.log(`username: ${process.env.WP_USER}`);
|
||||
console.log(`password: ${process.env.WP_PASSWORD}`);
|
||||
|
||||
const wp = new WPAPI({
|
||||
endpoint: process.env.WP_ENDPOINT,
|
||||
username: process.env.WP_USER,
|
||||
|
@ -21,7 +25,7 @@ const migrate = async (node, resource) => {
|
|||
console.log(`skipping "${node.slug}"`)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
const mobiledoc = JSON.parse(node.content)
|
||||
const rendered = renderer.render(mobiledoc);
|
||||
const mediaIds = await Promise.all(media.map(async (block) => {
|
||||
|
@ -38,14 +42,16 @@ const migrate = async (node, resource) => {
|
|||
return id;
|
||||
}
|
||||
catch (e) {
|
||||
console.error(`failed to upload "${block.attributes.href}"`)
|
||||
console.error(`Failed to download/upload "${block.attributes.href}" due to error: ${e.message}`)
|
||||
}
|
||||
}));
|
||||
})).catch((e) => {
|
||||
console.error(`upload error: ${e.message}`);
|
||||
});
|
||||
media.length = 0;
|
||||
|
||||
let featured = null;
|
||||
const { url, alt, caption } = node.image ||
|
||||
node.featured.image || {}
|
||||
node.featured.image || {};
|
||||
try {
|
||||
if (url) {
|
||||
featured = await wp.media()
|
||||
|
@ -58,7 +64,7 @@ const migrate = async (node, resource) => {
|
|||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error(`failed to upload featured "${url}"`)
|
||||
console.error(`failed to upload featured "${url}" due to error: ${e.message}`)
|
||||
}
|
||||
|
||||
console.log(`creating "${node.slug}"`);
|
||||
|
@ -75,15 +81,18 @@ const migrate = async (node, resource) => {
|
|||
})
|
||||
}
|
||||
catch (e) {
|
||||
console.error(`failed to create "${url}"`)
|
||||
console.error(`failed to create "${url}" due to error: ${e.message}`);
|
||||
}
|
||||
|
||||
await Promise.all(mediaIds.map(async (mediaId) => {
|
||||
if (mediaId) wp.media().id(mediaId).update({
|
||||
post: id,
|
||||
date_gmt: new Date(node.publishedAt)
|
||||
});
|
||||
}));
|
||||
// what's up with setting media to posts? the below snippet yields 'invalid parameter(s): post'...
|
||||
// await Promise.all(mediaIds.map(async (mediaId) => {
|
||||
// if (mediaId) wp.media().id(mediaId).update({
|
||||
// post: id,
|
||||
// date_gmt: new Date(node.publishedAt)
|
||||
// });
|
||||
// })).catch((error) => {
|
||||
// console.error(error);
|
||||
// });
|
||||
}
|
||||
|
||||
const download = async (location) => {
|
||||
|
@ -117,4 +126,6 @@ const findVacatures = () => {
|
|||
migrate(node, () => wp.vacatures()) :
|
||||
migrate(node, () => wp.pages());
|
||||
}, Promise.resolve());
|
||||
})()
|
||||
})().catch((e) => {
|
||||
console.error(`main loop error: ${e.message}`);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue