Skip to content

Instantly share code, notes, and snippets.

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

Hendrik HoverBaum

🌳
 I like 🌳🌳🌳 
View GitHub Profile
@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 / create-blogposts.js
Created March 22, 2018 13:12
Creating blogposts in Contentful.
const createBlogPosts = async (posts, assets, categories, managementToken, spaceId, simpleLog = console.log) => {
const client = contentful.createClient({
accessToken: managementToken,
logHandler: (level, data) => simpleLog(`${level} | ${data}`)
})
const space = await client.getSpace(spaceId)
const linkMap = new Map()
assets.forEach(asset => linkMap.set(asset.wpAsset.link, asset.fields.file['en-US'].url))
@HoverBaum
HoverBaum / create-and-publish-assets.js
Last active March 16, 2020 14:05
Create and publish assets in Contentful.
const createAndPublishAssets = (assets, managementToken, spaceId, locale, simpleLog = console.log) => new Promise(async resolve => {
simpleLog('Creating Contentful client')
const client = contentful.createClient({
accessToken: managementToken,
logHandler: (level, data) => simpleLog(`${level} | ${data}`)
})
const iterableAssets = makeIterator(assets)
const space = await client.getSpace(spaceId)
const cmsAssets = []
@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 / Readme.md
Last active March 4, 2020 05:34
Filter empty assets from Contentful export.

Using the Contentful Export tool I noticed that you can currently run into a situation where you export assets that have no files linked which will through an error when you try to pass the exported json into the Contentful Import tool as discussed in issue 95.

As a temporary solution I wrote myselve this script that you can pipe data through to filter out these malformed assets.

cat export.json | node filter-empty-assets.js > filtered-export.json

Now you can use the filteres-export.json for your import and it should work.

@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.
#
@HoverBaum
HoverBaum / bestCommentEver.js
Last active August 25, 2016 02:06
Ever write utterly horrible code? Put this at the top!
/*
, ,
/ \/ \
(/ //_ \_
.-._ \|| . \
\ '-._ _,:__.-"/---\_ \
______/___ '. .--------------------'~-'--.)__( , )\ \
`'--.___ _\ / | Here ,' \)|\ `\|
/_.-' _\ \ _:,_ Be Dragons " || (
.'__ _.' \'-/,`-~` |/