How to use parse-filepath - 10 common examples

To help you get started, we’ve selected a few parse-filepath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gatsbyjs / gatsby / packages / gatsby / lib / schema / markdown.js View on Github external
_.each(files, file => {
        const page = {}
        page.src = fs.readFileSync(file, `utf-8`)
        const ast = remark.parse(page.src)
        page.ast = ast
        page.bodyHTML = thing.Compiler.prototype.compile(page.ast)
        page.headings = select(ast, `heading`).map(heading => ({
          value: _.first(select(heading, `text`).map(text => text.value)),
          depth: heading.depth,
        }))
        const parsedFrontmatter = _.first(
          select(ast, `yaml`).map(heading => yaml.load(heading.value))
        )
        const relativeDirectory = parseFilepath(
          path.relative(`${directory}/pages/`, file)
        ).dirname

        // Create path.
        let filePath
        if (_.includes(relativeDirectory, `---`)) {
          // This is for my blog bricolage.io. This will be moved out soonish.
          filePath = `/${relativeDirectory.split(`---`)[1]}/`
        } else {
          filePath = createPath(path.join(directory, `pages`), file)
        }
        // TODO put linkPrefix in gatsby.config.js and somehow get certain
        // context stuff into gatsby-helpers.js
        // TODO post issue for why manifest paths wrong
        // TODO post stackoverflow about how to get static values — ping Joe.
        // Prefix stuff — just store this as another key "prefixedPath"?
github gatsbyjs / gatsby / packages / gatsby / lib / schema / images-schema.js View on Github external
mappedResults = mappedResults.map(image => {
            // Set path from FileName
            const parsedPath = parseFilepath(image.FileName)
            image.path = `/${_.kebabCase(`${parsedPath.dir}/${parsedPath.name}`)}/`
            // Render description as markdown (if set).
            if (image.Description) {
              image.Description = md.render(
                image.Description.replace(/<br>/g, `\n`)
              )
            }
            return image
          })
          const ImageType = new GraphQLObjectType({
github gatsbyjs / gatsby / lib / utils / post-build.js View on Github external
const copy = function copyFile(file, callback) {
      // Map file to path generated for that directory.
      // e.g. if file is in directory 2015-06-16-my-sweet-blog-post that got
      // rewritten to my-sweet-blog-post, we find that path rewrite so
      // our asset gets copied to the right directory.
      const parsed = parsePath(file)
      const relativePath = path.relative(`${directory}/pages`, file)
      let oldDirectory = parsePath(relativePath).dirname
      let newPath = ''

      // Wouldn't rewrite basePath
      if (oldDirectory === '') {
        oldDirectory = '/'
        newPath = `/${parsed.basename}`
      }

      if (!(oldDirectory === '/')) {
        const page = _.find(pages, p => {
          // Ignore files that start with underscore (they're not pages).
          if (p.file.name.slice(0, 1) !== '_') {
            return parsePath(p.requirePath).dirname === oldDirectory
          } else {
github gatsbyjs / gatsby / lib / utils / post-build.js View on Github external
const copy = function copyFile(file, callback) {
      // Map file to path generated for that directory.
      // e.g. if file is in directory 2015-06-16-my-sweet-blog-post that got
      // rewritten to my-sweet-blog-post, we find that path rewrite so
      // our asset gets copied to the right directory.
      const parsed = parsePath(file)
      const relativePath = path.relative(`${directory}/pages`, file)
      let oldDirectory = parsePath(relativePath).dirname
      let newPath = ''

      // Wouldn't rewrite basePath
      if (oldDirectory === '') {
        oldDirectory = '/'
        newPath = `/${parsed.basename}`
      }

      if (!(oldDirectory === '/')) {
        const page = _.find(pages, p => {
          // Ignore files that start with underscore (they're not pages).
          if (p.file.name.slice(0, 1) !== '_') {
            return parsePath(p.requirePath).dirname === oldDirectory
          } else {
            return false
          }
github laravel / elixir / src / tasks / compress.js View on Github external
const prepGulpPaths = function(src, baseDir, output) {
    // If you gave us an array of source files, and
    // no explicit output name, we'll need you to
    // be more specific.
    if (Array.isArray(src) && ! output) {
        Elixir.fail(
            'Please provide an output path ' +
            'for your mix.compress(src, output) call.'
        );
    }

    // If the user provided no output path at all, we
    // will do our best to provide a sensible default.
    if (! output) {
         let segments = filePath(src);

        output = segments.path.replace(
            segments.ext, `.min${segments.ext}`
        );
    }

    return new Elixir.GulpPaths()
        .src(src, baseDir)
        .output(output, filePath(Array.isArray(src) ? src[0] : src).base)
};
github gatsbyjs / gatsby / lib / utils / post-build.js View on Github external
oldDirectory = '/'
        newPath = `/${parsed.basename}`
      }

      if (!(oldDirectory === '/')) {
        const page = _.find(pages, p => {
          // Ignore files that start with underscore (they're not pages).
          if (p.file.name.slice(0, 1) !== '_') {
            return parsePath(p.requirePath).dirname === oldDirectory
          } else {
            return false
          }
        })

        if (page) {
          newPath = path.join(parsePath(page.path).path, parsed.basename)
        } else {
          // We couldn't find a page associated with this file. Probably
          // the file is in a directory of static files. In any case,
          // we'll leave the file directory alone.
          newPath = relativePath
        }
      }

      newPath = `${directory}/public/${newPath}`
      return fs.copy(file, newPath, error => callback(error))
    }
github gatsbyjs / gatsby / lib / utils / build-page / path-resolver.js View on Github external
export default function pathResolver(relativePath: string, pageData: {} = {}) {
  const data = {}

  data.file = parsePath(relativePath)

  // Remove the . from extname (.md -> md)
  data.file.ext = data.file.extname.slice(1)
  // Make sure slashes on parsed.dirname are correct for Windows
  data.file.dirname = slash(data.file.dirname)

  // Determine require path
  data.requirePath = slash(relativePath)

  // set the URL path (should this be renamed)
  // and now looking at it, it only needs a reference to pageData
  data.path = urlResolver(pageData, data.file)

  // Set the "template path"
  if (data.file.name === '_template') {
    data.templatePath = `/${data.file.dirname}/`
github gatsbyjs / gatsby / lib / utils / post-build.js View on Github external
const page = _.find(pages, p => {
          // Ignore files that start with underscore (they're not pages).
          if (p.file.name.slice(0, 1) !== '_') {
            return parsePath(p.requirePath).dirname === oldDirectory
          } else {
            return false
          }
        })

parse-filepath

Pollyfill for node.js `path.parse`, parses a filepath into an object.

MIT
Latest version published 6 years ago

Package Health Score

68 / 100
Full package analysis

Popular parse-filepath functions