Gulp Metalsmith rootpath - передайте мопсу соответствующий путь "глубина" - PullRequest
0 голосов
/ 06 ноября 2019

Я сканирую исходную папку, чтобы получить файлы мопса и создать HTML-страницы.

import path from 'path';
import gulp from 'gulp';
import metalsmith from 'metalsmith';
import metalsmithInlineSource from 'metalsmith-inline-source';
import metalsmithLayouts from 'metalsmith-layouts';
import metalsmithPug from 'metalsmith-pug';

const publicFolder = 'dist/tests';
const rootFolder = path.join(__dirname, '..');
const rootPath = require("metalsmith-rootpath");

function buildTestFixtures () {
  const promise = new Promise((resolve, reject) => {
    metalsmith(rootFolder)
      .source('test/sourcefolder')
      .destination(publicFolder)
      .clean(false)
      .use(metalsmithPug({
        doctype: 'html'
      }))
      .use(metalsmithInlineSource())
      .use(metalsmithLayouts({
        default: 'test.pug',
        directory: path.join(rootFolder, 'config', 'layouts'),
        doctype: 'html',
        engine: 'pug',
        pattern: '**/*.html'
      }))
      .use(rootPath())
      .build(error => {
        if (error) {
          reject(error);
        } else {
          resolve();
        }
      });
  });

Что мне нужно сделать, это:

Источник

enter image description here

Переменная rootPath, доступная для каждого файла pug, должна быть:

enter image description here

Поскольку мне нужно сделать какой-то ресурспути динамические, поэтому вместо жестко закодированного пути, как этот

link(src="../../../../css/main.css", type="text/css")

мне нужно:

link(src=`${rootPath}css/main.css`, type=`text/css`)

Но переменная rootPath не определена

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...