Skip to content

Instantly share code, notes, and snippets.

View HoverBaum's full-sized avatar
🌳
 I like 🌳🌳🌳 

Hendrik HoverBaum

🌳
 I like 🌳🌳🌳 
View GitHub Profile
const generateAssetsList = (posts, baseUrl, simpleLog = console.log) => new Promise(async resolve =>{
const apiURL = `${baseUrl.replace(/\/$/, '')}/wp-json/wp/v2/media`
simpleLog('Reducing posts to asset numbers')
let infosFetched = 0
// First add the featured_media images and get ther URLs.
const featuredAssets = await Promise.all(posts.reduce((all, post) => {
if (!post.featured_media) return all
return all.concat([{
mediaNumber: post.featured_media,
const getCategories = (posts, baseUrl, simpleLog = console.log) => new Promise(async resolve => {
const apiURL = `${baseUrl.replace(/\/$/, '')}/wp-json/wp/v2/categories`
// First reduce posts to an array of category numbers.
simpleLog('Reducing posts to category numbers')
const categories = await Promise.all(posts.reduce((all, post) => {
if(!post.category) return all
if(all.indexOf(post.category) > -1) return all
return all.concat([post.category])
}, [])
.map(async categoryNumber => {
const transformPosts = posts => posts.map(post => {
delete post._links
delete post.guid
delete post.excerpt
delete post.author
delete post.comment_status
delete post.ping_status
delete post.template
delete post.format
delete post.meta
const exportBlogposts = (apiUrl, log) => new Promise(resolve => {
const exportPageOfPosts = (apiUrl, page = 1, allPosts = []) => {
log(`Getting posts for page ${page}`)
const url = `${apiUrl}?page=${page}`
https.get(url, (res) => {
// When we get a 404 back we went one page over those with posts.
// So we are done now.
if(res.statusCode === 400) {
return resolve(allPosts)
}
@HoverBaum
HoverBaum / assetObject.js
Created March 26, 2018 08:37
Code example for blogpost about migrating from wordpress to Contentful.
[{
link: 'link to wordpress iage.jpg',
description: 'describe the image',
title: 'and title it',
postId: 'because linking back is nice'
}, ...]
@HoverBaum
HoverBaum / convertLocale.js
Created March 23, 2018 16:00
Convert a exported Spaces locale.
#!/usr/bin/env node
/* eslint-disable */
/**
* Replace the locale in an exported space.
*
* Usage:
* node changeSpaceLocale.js -l es-ES < space.json > translated.json
*
* The above will translate the space to Spanish (currently the only supported
* language to translate to).
@HoverBaum
HoverBaum / translateSpace.js
Last active March 21, 2018 13:21
Translate a space to a different locale for Contentful.
#!/usr/bin/env node
/**
* Replace the locale in an exported space.
*
* Usage:
* node changeSpaceLocale.js -l es-ES < space.json > translated.json
*
* The above will translate the space to Spanish (currently the only supported
* language to translate to).
*/
@HoverBaum
HoverBaum / commands
Created October 10, 2017 09:17
See branches on the commandline and create an alias for it.
git log --all --color --graph --pretty=format:'%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
git config --global alias.lg "log --all --color --graph --pretty=format:'%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
@HoverBaum
HoverBaum / example.js
Created April 28, 2017 16:50
Illustrating JS template string for HTML templating.
const numbers = [1, 2, 3, 4]
const list = html`
<ul>
${numbers.map(number => `<li>${number}</li>`)}
</ul>`
/*
At this point we have:
<ul>
@HoverBaum
HoverBaum / travis-example.yml
Last active April 18, 2017 16:40
Travis config to deploy a Hexo based site using FTP.
# FTP deploy Hexo based site using Travis-ci.org
# https://gist.github.com/HoverBaum/524528aec1032b29669fe9cc82dba066
#
# 1. Copy this file to the root of your repository, then rename it to '.travis.yml'
# 2. Replace 'YOUR NAME' and 'YOUR EMAIL'
# 3. Create "Environment Variables" in travis. Make sure to not show them in the output.
# - FTP_USER: The username for FTP transfer.
# - FTP_PASSWORD: Password for the user.
# 4. Replace "DOMAIN.TLD" with your FTP domain and maybe the path where to put things.
#