feat: revalidate my pages breadcrumbs on demand

This commit is contained in:
Simon Emanuelsson
2024-04-16 12:42:44 +02:00
committed by Michael Zetterberg
parent ba13a00b63
commit 0c4aa592cc
24 changed files with 322 additions and 57 deletions

View File

@@ -1,16 +1,25 @@
import type { Edges } from "@/types/requests/utils/edges"
import type { Lang } from "@/constants/languages"
import type { NodeRefs } from "@/types/requests/utils/refs"
import type { Lang } from "@/constants/languages"
/**
* Function to generate tag for initial refs request
*
* @param lang
* @param lang Lang
* @param identifier Should be uri for all pages and content_type_uid for
* everything else
* @param affix possible extra value to add to string, e.g lang:identifier:breadcrumbs:refs
* as it is the same entity as the actual page tag otherwise
* @returns string
*/
export function generateRefsResponseTag(lang: Lang, identifier: string) {
export function generateRefsResponseTag(
lang: Lang,
identifier: string,
affix?: string
) {
if (affix) {
return `${lang}:${identifier}:${affix}:refs`
}
return `${lang}:${identifier}:refs`
}
@@ -35,9 +44,15 @@ export function generateRefTag(
*
* @param lang Lang
* @param uid system.uid of entity
* @param affix possible extra value to add to string, e.g lang:uid:breadcrumbs
* as it is the same entity as the actual page tag otherwise
* @returns string
*/
export function generateTag(lang: Lang, uid: string) {
export function generateTag(lang: Lang, uid: string, affix?: string) {
if (affix) {
return `${lang}:${uid}:${affix}`
}
return `${lang}:${uid}`
}

3
utils/url.ts Normal file
View File

@@ -0,0 +1,3 @@
export function removeMultipleSlashes(str: string) {
return str.replaceAll(/\/\/+/g, "/")
}