Include content from metalsmith database #1

Open
opened 2018-10-03 20:10:49 -07:00 by RobLoach · 2 comments
RobLoach commented 2018-10-03 20:10:49 -07:00 (Migrated from github.com)

Check if the content exists in the metalsmith content database before reading from the filesystem.

Check if the content exists in the metalsmith content database before reading from the filesystem.
andyburke commented 2018-10-04 02:20:23 -07:00 (Migrated from github.com)

Can you elaborate? How would this look in practice?

The pattern is inspired by simple c-style includes, where the expectation is that the file lives on the filesystem somewhere. How would it live in the "metalsmith content database"?

Can you elaborate? How would this look in practice? The pattern is inspired by simple c-style includes, where the expectation is that the file lives on the filesystem somewhere. How would it live in the "metalsmith content database"?
RobLoach commented 2018-10-04 06:14:01 -07:00 (Migrated from github.com)

At this point:
https://github.com/andyburke/metalsmith-simple-includes/blob/master/index.js#L29-L31

Rather than retrieving the path to the Metalsmith directory and reading the file from the filesystem, we could....

  1. Check for files[path] beforehand to see if the file exists in the metalsmith database
  2. Grab that as the contents instead
  3. If files[path] doesn't exist, fallback to using fs.readFilePath

This way, you could stick plugins on the file before simple-includes, and those plugin changes would be present in the included content.

At this point: https://github.com/andyburke/metalsmith-simple-includes/blob/master/index.js#L29-L31 Rather than retrieving the path to the Metalsmith directory and reading the file from the filesystem, we could.... 1. Check for `files[path]` beforehand to see if the file exists in the metalsmith database 2. Grab that as the `contents` instead 3. If `files[path]` doesn't exist, fallback to using `fs.readFilePath` This way, you could stick plugins on the file before simple-includes, and those plugin changes would be present in the included content.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
andyburke/metalsmith-simple-includes#1
No description provided.