diff --git a/Multiple 404 caches/404.liquid b/Multiple 404 caches/404.liquid new file mode 100644 index 0000000..33fc66b --- /dev/null +++ b/Multiple 404 caches/404.liquid @@ -0,0 +1,70 @@ +{%- comment -%} +Relates to https://freakdesign.com.au/blogs/news/could-multiple-404-pages-be-better-than-one +{%- endcomment -%} + +
+ + {%- comment -%} Grab the current path {%- endcomment -%} + {%- assign pathDetails = request.path | split:'/' -%} + + {%- comment -%} Set the current cache type variable to `default` {%- endcomment -%} + {%- assign cacheType = 'default' -%} + + {%- comment -%} Let's break down the path to work out the type {%- endcomment -%} + {%- if pathDetails.size < 3 -%} + {%- assign cacheType = "A" -%} + {%- elsif pathDetails[1] == 'account' -%} + {%- assign cacheType = "A" -%} + {%- elsif pathDetails[1] == 'collections' or pathDetails[1] == 'products' -%} + {%- assign cacheType = "B" -%} + {%- elsif pathDetails[1] == 'pages' -%} + {%- assign cacheType = "C" -%} + {%- elsif pathDetails[1] == 'a' or pathDetails[1] == 'apps' -%} + {%- assign cacheType = "D" -%} + {%- endif -%} + + {%- comment -%} Optional: show different heading text based on cache type {%- endcomment -%} + {%- if cacheType == 'default' -%} +

{{ 'general.404.title' | t }}

+ {%- else -%} +

404
Cache type {{ cacheType }}

+ {%- endif -%} + + {%- comment -%} + Time to show different content based on the type. + I'm opting to use snippets for most of the different content but nothing stopping + you from just adding in the info directly. I find it's neater this way. + {%- endcomment -%} + + {%- case cacheType -%} + {%- when 'A' -%} + {%- comment -%} + Some fun if there's a very specific url used + On the experiements site the page title also changes but that code isn't shown here + {%- endcomment -%} + {%- if request.path == '/secret' -%} + + {%- else -%} + {%- include '404-root' -%} + {%- endif -%} + {%- when 'B' -%} + {%- include '404-collection' -%} + {%- when 'C' -%} + {%- include '404-page' -%} + {%- when 'D' -%} + {%- include '404-app' -%} + {%- else -%} +

{{ 'general.404.subtext_html' | t }}


+

{{ 'general.404.404_link' | t }}

+ {%- endcase -%} + + {%- comment -%} Add some debug/insights to help those following along this crazy adventure {%- endcomment -%} +
+ + URL at cache time: {{ request.path }}
+ pathDetails.size: {{ pathDetails.size }}
+ pathDetails[1]: {{ pathDetails[1] }}
+ cacheType: {{ cacheType }}
+
+
+
\ No newline at end of file diff --git a/Multiple 404 caches/README.md b/Multiple 404 caches/README.md new file mode 100644 index 0000000..8659e28 --- /dev/null +++ b/Multiple 404 caches/README.md @@ -0,0 +1,2 @@ +# Doing silly things with cached results of 404 pages. +Relates to the [Could multiple 404 pages be better than one?](https://freakdesign.com.au/blogs/news/could-multiple-404-pages-be-better-than-one) post on the freakdesign blog. \ No newline at end of file