Skip to content

Instantly share code, notes, and snippets.

@eexit
Last active August 3, 2023 22:41
Show Gist options
  • Select an option

  • Save eexit/8b547c62dd52e0940f8b7e701f861d99 to your computer and use it in GitHub Desktop.

Select an option

Save eexit/8b547c62dd52e0940f8b7e701f861d99 to your computer and use it in GitHub Desktop.

Revisions

  1. eexit revised this gist Mar 25, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ghost-image-to-cloudinary.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    // Usage:
    // $ npm install --loglevel=error cloudinary glob
    // $ npm i --no-package-lock --loglevel=error cloudinary glob
    // $ CLOUDINARY_URL=cloudinary://xxxx node ghost-image-to-cloudinary.js

    const cloudinary = require('cloudinary').v2,
  2. eexit revised this gist Mar 25, 2018. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions Ghost content update.md
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,14 @@
    2. Open in an editor that support Regex find/replace
    3. Search for:

    /content/images/\d{4}/(\w{3}|\d{2})/
    ```
    /content/images/\d{4}/(\w{3}|\d{2})/
    ```

    4. Replace by:

    http://res.cloudinary.com/{cloud-name}/image/upload/{transformations}/{folder}/
    ```
    http://res.cloudinary.com/{cloud-name}/image/upload/{transformations}/{folder}/
    ```

    It is adived to create a named tranformation in Cloudinary and use it in the URL so if you want to change what the transformation does, you can simply update the named transformation in Cloudinary instead of updating all your Cloudinary URL in your blog.
  3. eexit revised this gist Mar 25, 2018. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions Ghost content update.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    # Ghost content update

    1. Export your Ghost content (aka backup)
    2. Open in an editor that support Regex find/replace
    3. Search for:

    /content/images/\d{4}/(\w{3}|\d{2})/

    4. Replace by:

    http://res.cloudinary.com/{cloud-name}/image/upload/{transformations}/{folder}/

    It is adived to create a named tranformation in Cloudinary and use it in the URL so if you want to change what the transformation does, you can simply update the named transformation in Cloudinary instead of updating all your Cloudinary URL in your blog.
  4. eexit revised this gist Mar 25, 2018. 1 changed file with 24 additions and 12 deletions.
    36 changes: 24 additions & 12 deletions ghost-image-to-cloudinary.js
    Original file line number Diff line number Diff line change
    @@ -6,24 +6,33 @@ const cloudinary = require('cloudinary').v2,
    path = require('path'),
    glob = require('glob'),
    basedir = 'content/images/',
    dups = [],
    gopts = {
    use_filename: true,
    unique_filename: false,
    overwrite: false
    },
    getTags = (name) => {
    const dpr = name.match(/@(\d)x(?!.*@\dx)/);
    return dpr ? ['portfolio', `dpr${dpr[1]}`] : ['portfolio', 'dpr1'];
    return dpr ? ['blog', `dpr${dpr[1]}`] : ['blog', 'dpr1'];
    },
    upload = (f, cb) => {
    findDups = (f, cb) => {
    f = path.parse(f);
    f.date = f.dir.replace(basedir, '');

    if (dups.indexOf(f.name) >= 0) {
    console.error(new Error(`Found dup with ${f.name}`));
    return;
    }
    dups.push(f.name);
    cb(f);
    },
    upload = (f, cb) => {
    const fopt = Object.assign({}, gopts, {
    public_id: path.join(f.date, f.name),
    public_id: path.join('blog', f.name),
    tags: getTags(f.name)
    });

    // console.log(fopt); cb(); return;

    cloudinary.uploader.upload(path.join(f.dir, f.base), fopt, (err, res) => {
    if (err) { throw err; }
    console.log(res.url);
    @@ -34,12 +43,15 @@ const cloudinary = require('cloudinary').v2,
    glob(path.join(basedir, '**/*.jpg'), (err, files) => {
    if (err) { throw err; }
    let i = 0;
    (function(files) {
    return upload(files[i], () => {
    i++;
    if (i < files.length) {
    arguments.callee(files);
    }
    const run = (files) => {
    return findDups(files[i], (f) => {
    return upload(f, () => {
    i++;
    if (i < files.length) {
    run(files);
    }
    });
    });
    })(files);
    }
    return run(files);
    });
  5. eexit created this gist Mar 23, 2018.
    45 changes: 45 additions & 0 deletions ghost-image-to-cloudinary.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    // Usage:
    // $ npm install --loglevel=error cloudinary glob
    // $ CLOUDINARY_URL=cloudinary://xxxx node ghost-image-to-cloudinary.js

    const cloudinary = require('cloudinary').v2,
    path = require('path'),
    glob = require('glob'),
    basedir = 'content/images/',
    gopts = {
    use_filename: true,
    unique_filename: false,
    overwrite: false
    },
    getTags = (name) => {
    const dpr = name.match(/@(\d)x(?!.*@\dx)/);
    return dpr ? ['portfolio', `dpr${dpr[1]}`] : ['portfolio', 'dpr1'];
    },
    upload = (f, cb) => {
    f = path.parse(f);
    f.date = f.dir.replace(basedir, '');

    const fopt = Object.assign({}, gopts, {
    public_id: path.join(f.date, f.name),
    tags: getTags(f.name)
    });

    cloudinary.uploader.upload(path.join(f.dir, f.base), fopt, (err, res) => {
    if (err) { throw err; }
    console.log(res.url);
    cb();
    });
    };

    glob(path.join(basedir, '**/*.jpg'), (err, files) => {
    if (err) { throw err; }
    let i = 0;
    (function(files) {
    return upload(files[i], () => {
    i++;
    if (i < files.length) {
    arguments.callee(files);
    }
    });
    })(files);
    });