akabekobeko / npm-gatsby-remark-copy-relative-linked-files

Copies local files relative linked to/from markdown to your public folder with preserve directory structure.
MIT License
6 stars 3 forks source link

Copying indirectly linked files #4

Closed dansanderson closed 4 years ago

dansanderson commented 4 years ago

I have an edge case where I want to link from a Remark document to a static HTML file in the local source directory, and that file links to other files in the source directory via relative paths. Naturally, gatsby-remark-copy-relative-linked-files copies the file linked directly from the Remark document, but ignores the supplementary files.

A few suggestions, others welcome:

  1. Detect when linking to a file with a .html suffix, then recursively scan that file for links (maybe limited to relative links in the same directory) in anchor and media tags and copy those files as well.
  2. Detect a manifest file in the directory of a Remark file and copy those files as well as the linked file.
  3. Support a Remark syntax extension (such as a tagged code fence) in the file itself where additional files to copy can be listed without generating visible content.
    See [this generated report](report.html) for more information.

    ```copyfiles
    report.css
    diagram.png


gatsby-remark-table-of-contents does this tagged code fence trick, not sure how popular it is. It requires appearing before PrismJS in the plugin list.

Also note that I think gatsby-remark-copy-relative-linked-files is a good candidate for this feature request because it makes a named directory. If all files end up in the same relative path, then relative links do not need transformation.
akabekobeko commented 4 years ago

This issue is closed because #5 has been merged.