packages/build-tools/tasks/static-tasks.js
async function getPage(file) {
  config = config || (await asyncConfig());
  if (config.verbosity > 3) {
    log.dim(`Getting info for: ${file}`);
  }

  const url = path
    .relative(config.srcDir, file)
    .replace('.md', '.html')
    .split('/')
    .map(x => x.replace(/^[0-9]*-/, '')) // Removing number prefix `05-item` => `item`
    .join('/');
  const fileContents = await readFile(file, 'utf8');

  // https://www.npmjs.com/package/front-matter
  const { attributes, body, frontmatter } = fm(fileContents);

  const dirTree = url.split('/');

  let depth = url.split('/').filter(x => x !== 'index.html').length;

  let parent = dirTree[depth - 2];

  // Don't do it for homepage
  if (url === 'index.html') depth = 1;

  const page = {
    srcPath: file,
    url,
    depth,
    parent,
    meta: attributes,
    body: file.endsWith('.md') ? marked(body) : body,
  };

  return page;
}
async function getPage(file) {
  config = config || (await asyncConfig());
  if (config.verbosity > 3) {
    log.dim(`Getting info for: ${file}`);
  }

  const url = path
    .relative(config.srcDir, file)
    .replace('.md', '.html')
    .split('/')
    .map(x => x.replace(/^[0-9]*-/, '')) // Removing number prefix `05-item` => `item`
    .join('/');
  const fileContents = await readFile(file, 'utf8');

  // https://www.npmjs.com/package/front-matter
  const { attributes, body, frontmatter } = fm(fileContents);

  const dirTree = url.split('/');

  let depth = url.split('/').filter(x => x !== 'index.html').length;

  let parent = dirTree[depth - 2];

  // Don't do it for homepage
  if (url === 'index.html') depth = 1;

  const page = {
    srcPath: file,
    url,
    depth,
    parent,
    meta: attributes,
    body: file.endsWith('.md') ? marked(body) : body,
  };

  return page;
}
async function getPage ( file ) { config = config || ( await asyncConfig ( ) ) ; if ( config . verbosity > 3 ) { log . dim ( ` ${ file } ` ) ; } const url = path . relative ( config . srcDir , file ) . replace ( '.md' , '.html' ) . split ( '/' ) . map ( x => x . replace ( / ^[0-9]*- / , '' ) ) // Removing number prefix `05-item` => `item` . join ( '/' ) ; const fileContents = await readFile ( file , 'utf8' ) ; // https://www.npmjs.com/package/front-matter const { attributes , body , frontmatter } = fm ( fileContents ) ; const dirTree = url . split ( '/' ) ; let depth = url . split ( '/' ) . filter ( x => x !== 'index.html' ) . length ; let parent = dirTree [ depth - 2 ] ; // Don't do it for homepage if ( url === 'index.html' ) depth = 1 ; const page = { srcPath : file , url , depth , parent , meta : attributes , body : file . endsWith ( '.md' ) ? marked ( body ) : body , } ; return page ; }
Get data for a single page that is Markdown or HTML with Yaml front matter
@param {string} file - Path to source file
@returns {Promise<{srcPath: string, distPath: string, meta: object, body: string}>} page - Page Data
Get data for a single page that is Markdown or HTML with Yaml front matter