Esempio n. 1
0
// Main
function ScrollRack ( config ) {
    var caller = callerId.getData(),

        rootPath = path.dirname(caller.filePath),
        sourcePath = path.join(rootPath, config.files),
        destPath = path.join(rootPath, config.dest),
        ignoreFiles = config.ignore || ['*.js', '*.ts', '.DS_Store'],

        flags = [],
        md,
        metalsmith;


    // Parse command line arguments
    [].concat(process.argv, process.execArgv).forEach(function( arg ) {
        if( /^--/.test(arg) ) {
            flags.push(arg.replace(/^--/, ''));
        }
    });


    // Configure markdown
    md = markdown({
        typographer: true,
        linkify: true,
        breaks: true,
        langPrefix: 'hljs ',
        highlight: escape
    });
    md.parser
        .use(require('markdown-it-footnote'))
        .use(require('markdown-it-smartarrows'))
        .use(require('markdown-it-anchor'), {
            level: 2,
            permalink: true,
            renderPermalink: renderPermalink
        });


    // Build
    metalsmith = Metalsmith(__dirname)
        .source(sourcePath)
        .destination(destPath)
        .ignore(ignoreFiles)
        .use(partials({
            directory: 'templates/partials'
        }))
        .use(helpers({
            directory: 'templates/helpers'
        }))

        .use(md)
        .use(branch(['**/*.html', '!*.html'])
            .use(permalinks({
                pattern: ':category/:title'
            })
        ))
        .use(normalizeAssetPath())

        .use(nav(config.nav))
        .use(sections({
            nav: 'nav',
            template: 'templates/sections.hbs',
            redirect: config.redirect || true
        }))
        .use(metadata({
            flags: flags
        }))
        .use(neighbours())

        .use(layouts({
            engine: 'handlebars',
            default: 'page.hbs',
            directory: 'templates'
        }))
        .use(hyphenate({
            elements: ['p', 'blockquote']
        }))
        .use(sass({
            file: 'scss/style.scss',
            sourceMap: true,
            outputStyle: 'expanded'
        }));

    // Copy files
    metalsmith
        .use(copy(
            [{
                pattern: __dirname + '/assets/js/*.js',
                target: ''
            }, {
                pattern: theme(config.code_theme),
                target: '',
                rename: 'theme.css'
            }, {
                pattern: __dirname + '/assets/favicon.ico',
                target: ''
            }].concat(
                // Conditionally set assets
                config.assets ? [{
                    pattern: path.join(rootPath, config.assets, '/**/*'),
                    target:  'assets'
                }] : []
            )
        ));


    // Activate browser sync?
    if (~flags.indexOf('serve')) {
        metalsmith
            .use(serve({
                port: config.port || 8080
            }))
            .use(rebuild({
                pattern: [
                    path.join(sourcePath + '/**/*'),
                    path.join(__dirname + '/scroll-rack.js'),
                    path.join(__dirname + '/plugins/**/*'),
                    path.join(__dirname + '/templates/**/*'),
                    path.join(__dirname + '/scss/**/*.scss'),
                    path.join(__dirname + '/assets/**/*')
                ],
                livereload: true
            }));
    }

    metalsmith
        .build(function(err) {
            if (err) { throw err; }
            log(chalk.green.bold('Build complete!'));
            if (~flags.indexOf('serve')) {
                open('http://localhost:'+ (config.port || 8080) + '/');
            }
            else if ( _.isFunction(config.callback) ) {
                config.callback();
            }
        });
}
Esempio n. 2
0
exports.metalsmith = function() {
  var _removeEmptyTokens = function removeEmptyTokens(token) {
    if (token.length > 0) {return token};
  };
  var metalsmith = Metalsmith(__dirname)
    .concurrency(100)
    .source("../src")
    .destination("../build")
    .use(less({
      pattern: "**/less/style.less",
      useDynamicSourceMap: true
    }))
    .use(ignore([
      '**/less/*.less',
      'content/languages/**/*',
      'assets/images/**/*.ai',
      'content/reference/api_old.md'
    ]))
    .use(cleanCSS({
      files: '**/*.css'
    }))
    .use(msIf(
      (!process.env.TRAVIS_PULL_REQUEST || process.env.TRAVIS_PULL_REQUEST === 'false'),
      apidoc({
        src: '../api-node/',
        config: '../api-node/',
        destFile: 'content/reference/api.md',
        includeFilters: ['.*[vV]iews[^.]*\\.js$', 'lib/AccessTokenController.js']
      })
    ))
    .use(partials({
      directory: '../templates/partials'
    }))
    .use(fileMetadata([
      {pattern: "content/**/*.md", metadata: {"lunr": true, "assets": '/assets', "branch": gitBranch}}
    ]))
    .use(msIf(
      environment === 'development',
      fileMetadata([
        {pattern: "content/**/*.md", metadata: {"development": true}}
      ])
    ))
    .use(precompile({
      directory: '../templates/precompile',
      dest: 'assets/js/precompiled.js',
      knownHelpers: {
        'each': true,
        'if': true
      }
    }))
    .use(moveUp(['content/**/*']))
    .use(paths())
    .use(helpers({
      directory: '../templates/helpers'
    }))
    .use(collections({
      guide: {
        pattern: 'guide/:section/*.md',
        sortBy: 'order',
        orderDynamicCollections: [
          'getting-started',
          'tools-and-features',
          'how-to-build-a-product'
        ]
      },
      reference: {
        pattern: 'reference/*md',
        sortBy: 'order'
      },
      datasheet: {
        pattern: 'datasheets/*.md',
        sortBy: 'order'
      },
      support: {
        pattern: 'support/:section/*.md',
        sortBy: 'order',
        orderDynamicCollections: [
          'support-and-fulfillment',
          'troubleshooting',
          'inquiries'
        ]
      }
    }))
    .use(fork({
      key: 'devices',
      redirectTemplate: './templates/redirector.jade'
    }))
    .use(inPlace({
      engine: 'jade',
      pattern: '**/*.jade'
    }))
    .use(copy({
      pattern: '**/*.jade',
      extension: '.html',
      move: true
    }))
    .use(inPlace({
      engine: 'handlebars',
      pattern: '**/*.md'
    }))
    .use(markdown())
    .use(autotoc({
      selector: 'h2, h3',
      pattern: '**/**/*.md'
    }))
    .use(lunr({
      indexPath: 'search-index.json',
      fields: {
        contents: 1,
        title: 10
      },
      pipelineFunctions: [
        _removeEmptyTokens
      ]
    }))
    .use(templates({
      engine: 'handlebars',
      directory: '../templates'
    }))
    .use(permalinks({
      relative: false
    }))
    .use(redirect({
      '/start': '/guide/getting-started/intro',
      '/guide': '/guide/getting-started/intro',
      '/guide/photon/': '/guide/photon/start',
      '/guide/core/': '/guide/core/start',
      '/reference': '/reference/firmware',
      '/datasheets': '/datasheets/kits/photon/',
      '/guide/getting-started': '/guide/getting-started/intro',
      '/guide/how-to-build-a-product': '/guide/how-to-build-a-product/intro/',
      '/guide/tools-and-features': '/guide/tools-and-features/intro',
      '/support': '/support/support-and-fulfillment/menu-base',
      "/photon" : "/",
      "/photon/start" : "/guide/getting-started/start",
      "/photon/connect" : "/guide/getting-started/connect",
      "/photon/modes" : "/guide/getting-started/modes",
      "/photon/tinker" : "/guide/getting-started/tinker",
      "/photon/examples" : "/guide/getting-started/examples",
      "/photon/dev" : "/guide/tools-and-features/dev",
      "/photon/dashboard" : "/guide/tools-and-features/dashboard",
      "/photon/firmware" : "/reference/firmware",
      "/photon/api" : "/reference/api",
      "/photon/javascript" : "/reference/javascript",
      "/photon/ios" : "/reference/ios",
      "/photon/photon-datasheet" : "/datasheets/photon-datasheet",
      "/photon/p1-datasheet" : "/datasheets/p1-datasheet",
      "/photon/shields" : "/datasheets/photon-shields",
      "/photon/cli" : "/reference/cli",
      "/photon/ifttt" : "/guide/tools-and-features/ifttt",
      "/photon/webhooks" : "/guide/tools-and-features/webhooks",
      "/photon/hackathon" : "/guide/tools-and-features/hackathon",
      "/core" : "/guide/getting-started/intro/core",
      "/core/start" : "/guide/getting-started/start/core",
      "/core/connect" : "/guide/getting-started/connect/core",
      "/core/modes" : "/guide/getting-started/modes/core",
      "/core/tinker" : "/guide/getting-started/tinker/core",
      "/core/examples" : "/guide/getting-started/examples/core",
      "/core/dev" : "/guide/tools-and-features/dev/core",
      "/core/dashboard" : "/guide/tools-and-features/dashboard/core",
      "/core/firmware" : "/reference/firmware",
      "/core/api" : "/reference/api",
      "/core/javascript" : "/reference/javascript",
      "/core/ios" : "/reference/ios",
      "/core/hardware" : "/datasheets/core-datasheet",
      "/core/shields" : "/datasheets/core-shields",
      "/core/cli" : "/reference/cli",
      "/core/ifttt" : "/guide/tools-and-features/ifttt/core",
      "/core/webhooks" : "/guide/tools-and-features/webhooks/core",
      "/core/hackathon" : "/guide/getting-started/hackathon/core",
      "/firmware" : "/reference/firmware",
      "/api" : "/reference/api",
      "/cli" : "/reference/cli",
      "/javascript" : "/reference/javascript",
      "/ios" : "/reference/ios",
      "/mobile" : "/reference/ios",
      "/start" : "/guide/getting-started/start",
      "/connect" : "/guide/getting-started/connect",
      "/modes" : "/guide/getting-started/modes",
      "/tinker" : "/guide/getting-started/tinker",
      "/build" : "/guide/getting-started/build",
      "/examples" : "/guide/getting-started/examples",
      "/dev" : "/guide/tools-and-features/dev",
      "/dashboard" : "/guide/tools-and-features/dashboard",
      "/cli" : "/guide/tools-and-features/cli",
      "/monitor" : "/guide/tools-and-features/monitor",
      "/ifttt" : "/guide/tools-and-features/ifttt",
      "/firmware" : "/reference/firmware",
      "/webhooks" : "/guide/tools-and-features/webhooks",
      "/hackathon" : "/guide/getting-started/hackathon",
      "/photon-datasheet" : "/datasheets/photon-datasheet",
      "/p1-datasheet" : "/datasheets/p1-datasheet",
      "/hardware" : "/datasheets/core-datasheet",
      "/photon-shields" : "/datasheets/photon-shields",
      "/shields" : "/datasheets/photon-shields",
      "/photon/hardware" : "/datasheets/photon-datasheet",
      "/troubleshooting" : "/support/troubleshooting/common-issues",
      "/help" : "/support/troubleshooting/common-issues",
      "/faq" : "/support/support-and-fulfillment/faq"
    }))
    .use(msIf(
      environment !== 'development',
      compress({overwrite: true})
    ));

  return metalsmith;
};