sounisi5011/metalsmith-netlify-published-date

Specify the Metalsmith plugins that process dates

Closed this issue · 2 comments

Currently, this plugin defines the contentsConverter option and the contentsEquals option, which are specified when you want to exclude constantly changing time information etc. from the content of the page.

However, these options are not useful by default.
It is necessary to write a conversion / comparison function using cheerio etc. in order to delete the element which stored fluctuating date information etc.
This will make it very difficult to use.

Instead, we propose the option to configure the Metalsmith plugins that generate HTML files using the metadata that this plugin adds.

For example, the configuration file #19 can be written like this:

{
  "plugins": {
    "@sounisi5011/metalsmith-netlify-published-date": {
      "plugins": {
        "metalsmith-in-place": {
          "setFilename": true
        }
      }
    }
  }
}

There is no need to make extra settings.
metalsmith-in-place generates valid HTML.
Also, because it uses metadata, it is not necessary to exclude date-dependent elements.
It is possible to compare the contents of the generated file with the preview on Netlify.

There is a nasty problem.
It is restoration of Metalsmith's files object.

Plugins specified in the plugins option will be executed many times with different metadata.
In that case, how do you rewind the files object passed to the plugins?

If we deep clone the files object and pass it to the plugins, the plugin that operates using object references will not work.
For example, metalsmith-pug-extra implements rerender with file object references.

References to the files object and the metadata object for each stored file must be passed to the plugin as is.

There is no need to make extra settings.

That's wrong. Unfortunately, it won't work with the plugins option alone.

The plugins we are creating do not know what plugins specified in the plugins option will handle.
It is a black box.
In other words, the file before conversion can not be associated with the file after conversion.

For example, when converting a Pug template file to HTML, a new file is added with the file name extension .pug replaced with the extension .html.
However, such rules do not always apply.
Maybe the extension .html.pug is set to be replaced by .htm.
Our plugin will not be able to determine that.

In addition, our plugin will need to know the rules for converting Metalsmith's filename to a preview URL on Netlify.
The preview URL should generally be obtained by combining the Metalsmith file path with the preview page domain.
However, this rule is not absolute either.
An environment may exist where files under a specific directory are published to the Netlify root directory.

At a minimum, the option to specify how plugins specified in the "plugins" option convert files is required.
For example:

{
  "plugins": {
    "@sounisi5011/metalsmith-netlify-published-date": {
      "plugins": {
        "metalsmith-in-place": {
          "setFilename": true
        }
      },
      "convertRules": [
        {
          "from": { "regex": "\\.pug$" },
          "to": ".html"
        }
      ]
    }
  }
}