Skip to content

Instantly share code, notes, and snippets.

@daviddarnes
Last active June 10, 2023 01:17
Show Gist options
  • Select an option

  • Save daviddarnes/eb956c1a8b57f4249ea57516b06ca89e to your computer and use it in GitHub Desktop.

Select an option

Save daviddarnes/eb956c1a8b57f4249ea57516b06ca89e to your computer and use it in GitHub Desktop.

Revisions

  1. daviddarnes revised this gist Dec 18, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ const ghostContentAPI = require("@tryghost/content-api");
    const api = new ghostContentAPI({
    url: 'https://demo.ghost.io',
    key: '22444f78447824223cefc48062',
    version: "v2"
    version: "v4"
    });

    const template = `
  2. daviddarnes revised this gist Aug 12, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -39,12 +39,12 @@ gulp.task('ghost', async function() {
    const { published_at, slug } = post;

    return new File({
    path: `${published_at.slice(0,10)}-${slug}.md`,
    contents: Buffer.from(templateFunction(post))
    path: `${published_at.slice(0,10)}-${slug}.md`,
    contents: Buffer.from(templateFunction(post))
    });
    });

    // Gulp specific stream stuff
    return streamArray(files)
    .pipe(gulp.dest('./_posts'));
    .pipe(gulp.dest('./_posts'));
    });
  3. daviddarnes revised this gist Aug 12, 2019. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    {
    "name": "ghost-to-jekyll",
    "version": "1.0.0",
    "description": "Import Ghost into a Jekyll site",
    "main": "gulpfile.js",
    "scripts": {
    "test": "gulp ghost"
    },
    "author": "David Darnes",
    "license": "MIT",
    "dependencies": {
    "@tryghost/content-api": "^1.2.7",
    "gulp": "^4.0.2",
    "handlebars": "^4.1.2",
    "stream-array": "^1.1.2",
    "vinyl": "^2.2.0"
    }
    }
  4. daviddarnes revised this gist Aug 12, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ tags:
    {{{ html }}}
    `;

    const templateFunction = Handlebars.compile(template);
    const templateFunction = Handlebars.compile(template.trim());

    gulp.task('ghost', async function() {
    const posts = await api.posts
    @@ -43,8 +43,8 @@ gulp.task('ghost', async function() {
    contents: Buffer.from(templateFunction(post))
    });
    });

    // Gulp specific stream stuff
    return streamArray(files)
    .pipe(gulp.dest('./_posts'));
    });
    });
  5. daviddarnes revised this gist Aug 12, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ const api = new ghostContentAPI({
    version: "v2"
    });

    const markdownTemplate = `
    const template = `
    ---
    title: {{ title }}
    excerpt: {{{ excerpt }}}
    @@ -23,7 +23,7 @@ tags:
    {{{ html }}}
    `;

    const templateFunction = Handlebars.compile(markdownTemplate);
    const templateFunction = Handlebars.compile(template);

    gulp.task('ghost', async function() {
    const posts = await api.posts
  6. daviddarnes revised this gist Aug 12, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ tags:
    {{{ html }}}
    `;

    const markdownTemplateFn = Handlebars.compile(markdownTemplate);
    const templateFunction = Handlebars.compile(markdownTemplate);

    gulp.task('ghost', async function() {
    const posts = await api.posts
    @@ -40,7 +40,7 @@ gulp.task('ghost', async function() {

    return new File({
    path: `${published_at.slice(0,10)}-${slug}.md`,
    contents: Buffer.from(markdownTemplateFn(post))
    contents: Buffer.from(templateFunction(post))
    });
    });

  7. daviddarnes revised this gist Aug 12, 2019. 1 changed file with 25 additions and 26 deletions.
    51 changes: 25 additions & 26 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,7 @@
    const File = require('vinyl');
    const gulp = require("gulp");
    const hb = require('gulp-hb');
    const Handlebars = require('handlebars');
    const streamArray = require('stream-array');
    const through = require('through2');
    const ghostContentAPI = require("@tryghost/content-api");

    const api = new ghostContentAPI({
    @@ -11,17 +10,7 @@ const api = new ghostContentAPI({
    version: "v2"
    });

    gulp.task('ghost', async function() {
    const posts = await api.posts
    .browse({
    include: "tags,authors",
    limit: "all"
    })
    .catch(err => {
    console.error(err);
    });

    const markdownTemplate = `
    const markdownTemplate = `
    ---
    title: {{ title }}
    excerpt: {{{ excerpt }}}
    @@ -32,20 +21,30 @@ tags:
    {{/each}}
    ---
    {{{ html }}}
    `;
    `;

    const markdownTemplateFn = Handlebars.compile(markdownTemplate);

    return streamArray(posts)
    .pipe(through.obj(function (post, encoding, callback) {
    const { published_at, slug } = post;
    gulp.task('ghost', async function() {
    const posts = await api.posts
    .browse({
    include: "tags,authors",
    limit: "all"
    })
    .catch(err => {
    console.error(err);
    });

    const file = new File({
    path: `${published_at.slice(0,10)}-${slug}.md`,
    contents: new Buffer.from(markdownTemplate.trim()),
    data: post,
    });
    this.push(file);
    callback();
    }))
    .pipe(hb())
    const files = posts.map(post => {
    const { published_at, slug } = post;

    return new File({
    path: `${published_at.slice(0,10)}-${slug}.md`,
    contents: Buffer.from(markdownTemplateFn(post))
    });
    });

    // Gulp specific stream stuff
    return streamArray(files)
    .pipe(gulp.dest('./_posts'));
    });
  8. daviddarnes revised this gist Aug 11, 2019. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -36,8 +36,10 @@ tags:

    return streamArray(posts)
    .pipe(through.obj(function (post, encoding, callback) {
    const { published_at, slug } = post;

    const file = new File({
    path: `${post.published_at.slice(0,10)}-${post.slug}.md`,
    path: `${published_at.slice(0,10)}-${slug}.md`,
    contents: new Buffer.from(markdownTemplate.trim()),
    data: post,
    });
  9. daviddarnes revised this gist Aug 11, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,8 @@ const through = require('through2');
    const ghostContentAPI = require("@tryghost/content-api");

    const api = new ghostContentAPI({
    url: 'https://gatsby.ghost.io',
    key: '9cc5c67c358edfdd81455149d0',
    url: 'https://demo.ghost.io',
    key: '22444f78447824223cefc48062',
    version: "v2"
    });

  10. daviddarnes revised this gist Aug 8, 2019. 1 changed file with 11 additions and 8 deletions.
    19 changes: 11 additions & 8 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -21,12 +21,8 @@ gulp.task('ghost', async function() {
    console.error(err);
    });

    return streamArray(posts)
    .pipe(through.obj(function (post, encoding, callback) {
    const file = new File({
    path: `${post.published_at.slice(0,10)}-${post.slug}.md`,
    contents: new Buffer.from(
    `---
    const markdownTemplate = `
    ---
    title: {{ title }}
    excerpt: {{{ excerpt }}}
    feature_image: {{ feature_image }}
    @@ -35,12 +31,19 @@ tags:
    - {{ this.slug }}
    {{/each}}
    ---
    {{{ html }}}`),
    {{{ html }}}
    `;

    return streamArray(posts)
    .pipe(through.obj(function (post, encoding, callback) {
    const file = new File({
    path: `${post.published_at.slice(0,10)}-${post.slug}.md`,
    contents: new Buffer.from(markdownTemplate.trim()),
    data: post,
    });
    this.push(file);
    callback();
    }))
    .pipe(hb())
    .pipe(gulp.dest('./_posts'));
    });
    });
  11. daviddarnes created this gist Aug 8, 2019.
    46 changes: 46 additions & 0 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    const File = require('vinyl');
    const gulp = require("gulp");
    const hb = require('gulp-hb');
    const streamArray = require('stream-array');
    const through = require('through2');
    const ghostContentAPI = require("@tryghost/content-api");

    const api = new ghostContentAPI({
    url: 'https://gatsby.ghost.io',
    key: '9cc5c67c358edfdd81455149d0',
    version: "v2"
    });

    gulp.task('ghost', async function() {
    const posts = await api.posts
    .browse({
    include: "tags,authors",
    limit: "all"
    })
    .catch(err => {
    console.error(err);
    });

    return streamArray(posts)
    .pipe(through.obj(function (post, encoding, callback) {
    const file = new File({
    path: `${post.published_at.slice(0,10)}-${post.slug}.md`,
    contents: new Buffer.from(
    `---
    title: {{ title }}
    excerpt: {{{ excerpt }}}
    feature_image: {{ feature_image }}
    tags:
    {{#each tags}}
    - {{ this.slug }}
    {{/each}}
    ---
    {{{ html }}}`),
    data: post,
    });
    this.push(file);
    callback();
    }))
    .pipe(hb())
    .pipe(gulp.dest('./_posts'));
    });