ProjectEvergreen / greenwood

Greenwood is your workbench for the web, embracing web standards from the ground up to empower your stack from front to back.
https://www.greenwoodjs.io
MIT License
97 stars 9 forks source link

Not Found (404) Page #240

Closed thescientist13 closed 2 years ago

thescientist13 commented 4 years ago

Type of Change

Summary

Per conversations coming out of https://github.com/ProjectEvergreen/greenwood/pull/225#pullrequestreview-305581464, it seems that there is a greater conversation to be had around the expectations of what a 404 page should be for Greenwood, so tracking that as a top level item in its own issues.

Details

Some questions around the feature to be answered are:

  1. Should Greenwood have a default 404 template / page / md?
  2. Should Greenwood only care that a user has one?
  3. Where should a default 404 live?

In general, common behavior would / could be:

  1. If user has src/pages/404.md scaffold it out from page-template.js
  2. If user has no 404.md... ????
thescientist13 commented 4 years ago

Not sure what others think, but I think if Greenwood wants to provide a default 404 page, it should be as part of a plugin, e.g. #200

@hutchgrant Can you provide a brief write up of what you think this feature should do and what user would / should expect from it? That can help us drive the addition of this feature.

hutchgrant commented 4 years ago

No I don't think 404 should be a plugin. It needs to be included by default and plugins can be made to change those default settings. Can you imagine installing wordpress, drupal, or gatsby and then needed a plugin just for a 404 page, not necessarily just adding a theme page etc? Every modern CMS and many static site generator provides 404s by default.

https://www.gatsbyjs.org/docs/add-404-page/

  1. a 404 page should be provided by default
  2. a 404 page should be easily overridden
  3. a 404 page should be themeable and extensible
  4. a 404 page should be viewable in development
  5. a 404 page should be viewable when testing production builds
  6. a 404 page should be added to graph in order to be serialized along with other pages
  7. a 404 page should be accessible from the lit-redux-router wildcard route client side SPA
  8. a 404 page should be copied to the build folder as 404.html when serialized

The easiest method to do this is using our markdown loader, which enables the use of page templates, to easily theme and write a 404 page. We simply include a 404.md within the core /src/templates folder, which can easily be overridden from the user's workspace e.g. /src/pages/404.md. We add it to the graph so it's serialized along with every other page. Then we add a postSerialize function to copy the file to the 404.html in the root of our build(public) folder.

aholtzman commented 4 years ago

I agree that the 404 page should be included by default and easily customizable and placed in a folder that would be logical for the user (such as /pages or /templates).

The primary issue that I see maybe coming up from this is if the final rendered site is deployed from a service that does not handle a 404.html page like Netlify... is there a fallback or way to inform the user to handle 404s is a different way? Maybe this is not even an issue (my ignorance).

Taking a beat and documenting this feature first does seem like a good way of approaching it with a clear and thought out plan (and probably good practice in general). I kind of use a similar technique with photography called 'previsualization' where you start by imagining the desired finish image and then start to break down how to achieve it, what techniques, equipment, modifications would be needed and how they would be used to reach the end goal.

I can see the super charged 'smart' 404 being a plugin - a cool feature that some people may want but is probably not for everyone.

thescientist13 commented 4 years ago

Ok, let's proceed with this then, and I will close #176 / #225 as this isn't really a bug, just an undeveloped / undocumented feature.

Let's keep the Greenwood 404.md we bundle simple and treat it like a page, leveraging whatever the default page-template.js is. We can then use a plugin down the road to provide a more super powered option of handling 404s. (like with a search feature).

thescientist13 commented 4 years ago

Defer to #200

thescientist13 commented 4 years ago

Can incorporate these thoughts re: 404 as a plugin

thescientist13 commented 3 years ago

As part of #669 and its outstanding TODO around server command based testing, it would be good to ensure we cover as much 404 specific route handling as we can when we work on this.

Also would be good to keep this in line with needs around default workspace vs node_modules route handling, as being discussed in https://github.com/ProjectEvergreen/greenwood/discussions/691.