Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings and a strict mode #427

Open
not-my-profile opened this issue Jun 4, 2023 · 3 comments
Open

Warnings and a strict mode #427

not-my-profile opened this issue Jun 4, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@not-my-profile
Copy link
Contributor

not-my-profile commented Jun 4, 2023

With Lume there are currently many opportunities to make small mistakes that will not be reported. For example:

  • Mistyping the source path given to Site.copy (if the file doesn't exist, nothing will happen).
  • Using Site.copy multiple times for the same source path with different destinations (only the last call will take effect).
  • Making a typo in a variable in a nunjuck template (i.e. referencing undefined data).
  • Making a typo when specifying a tag name (either in the metadata or when calling e.g. search.pages).

I think it would be nice if such likely usage errors would be detected and reported. The CLI could even have a --strict mode that could fail if any such problem was to be detected for usage within CIs. Detecting the mistyped tags would require the ability to optionally declare them with e.g. lume({tags: ["post"]}, ...).

What do you think about this matter?

@oscarotero
Copy link
Member

oscarotero commented Jun 4, 2023

There are some interesting points here. Not sure if a strict mode is a good idea because it would be hard to implement some of the checkings.

For example, there are many ways to select and copy a file:

  • Using a extension: site.copy([".jpg"]
  • Using the file name: site.copy("image/one.jpg")
  • Using a folder name: site.copy("image")

The same file can match to multiple conditions, and this is okay. For example, you may want to copy all jpg files to a specific directory, except a couple of files that have a different destination. The only thing we can do is if the same condition was already used (for example, calling site.copy("image") twice), we can show a warning.

Making a typo in a variable in a nunjuck template (i.e. referencing undefined data).

Nunjucks has already an option for that (throwOnUndefined) that by default is false.

Making a typo when specifying a tag name (either in the metadata or when calling e.g. search.pages).

I don't understand this. It's okay to filter by non existing fields. For example, you may want to get all pages with the category "lume", so you run search.pages("category=lume"). There may be pages without the category defined (because they are different types of pages that don't need it). What do you think it should happen here?

@not-my-profile
Copy link
Contributor Author

I think the best way to address the pitfall of the current Site.copy API is to enable the copying of one file to multiple destinations and perform the deprecations suggested in #428 (comment).

I don't understand this.

I agree that it's okay to filter on non-existing fields. I was talking of some way of validating the metadata defined in frontmatters. I guess this could be achieved with an event handler.

If you were to define the schema for your data with e.g. JSON schema we could even validate queries. E.g. if you have defined that there only are the tags foo, bar and baz then filtering for a tag orange could be detected as an error. But yeah validating data is of course more important than validating queries.

@oscarotero
Copy link
Member

Schema validation is a nice idea for a plugin. It could be a preprocessor that validate all pages before rendering and show warnings when a page has a different scheme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants