diff --git a/helpers/generateSw.js b/helpers/generateSw.js index 28ff7e9..d7c946a 100644 --- a/helpers/generateSw.js +++ b/helpers/generateSw.js @@ -40,6 +40,15 @@ generateSW({ clientsClaim: true, mode: 'production', runtimeCaching: [ + { + handler: 'NetworkOnly', + urlPattern: (option) => + ['/illustrate', '/sitemap.xml'].some((item) => { + console.log(option.url.pathname.includes(item)); + return option.url.pathname.includes(item); + }), + options: {} + }, { handler: 'CacheFirst', urlPattern: (options) => options.request.destination === 'font', diff --git a/helpers/vite-generateSw.ts b/helpers/vite-generateSw.ts index 4a66813..60ad763 100644 --- a/helpers/vite-generateSw.ts +++ b/helpers/vite-generateSw.ts @@ -533,6 +533,11 @@ export default function vitePluginWorkbox({ mode }: ConfigParams): PluginOption clientsClaim: true, mode: mode, runtimeCaching: [ + { + handler: 'NetworkOnly', + urlPattern: (option) => ['/illustrate', '/sitemap.xml'].includes(option.url.pathname), + options: {} + }, { handler: 'CacheFirst', urlPattern: (options) => options.request.destination === 'font', diff --git a/src/router/router.ts b/src/router/router.ts index 16d255f..10a0cb3 100644 --- a/src/router/router.ts +++ b/src/router/router.ts @@ -26,6 +26,7 @@ interface Meta { description: string; imageUrl: string; book?: boolean; + draft?: boolean; } /** user route */ diff --git a/src/utils/file.ts b/src/utils/file.ts index e2ea872..d1acfea 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -1,5 +1,11 @@ type IFileDataType = 'text' | 'dataurl' | 'binrary'; +/** + * + * @description read file + * @param file + * @param type + */ export function readFile(file: File, type: 'text'): Promise; export function readFile(file: File, type: 'dataurl'): Promise; export function readFile(file: File, type: 'binrary'): Promise; diff --git a/src/viewer/hooks/useArticles.ts b/src/viewer/hooks/useArticles.ts index cb4b725..895ff3a 100644 --- a/src/viewer/hooks/useArticles.ts +++ b/src/viewer/hooks/useArticles.ts @@ -11,7 +11,9 @@ export function useArticles() { const articles = getChildrenById(routes, Articles_ID); // the latest articles are displayed first - articles.sort((a, b) => new Date(b.meta!.date).getTime() - new Date(a.meta!.date).getTime()); + articles + .filter((article) => !article.meta!.draft) + .sort((a, b) => new Date(b.meta!.date).getTime() - new Date(a.meta!.date).getTime()); return articles; }, [routes]); diff --git a/src/viewer/hooks/useBooks.ts b/src/viewer/hooks/useBooks.ts index 92d0ad2..2efbb82 100644 --- a/src/viewer/hooks/useBooks.ts +++ b/src/viewer/hooks/useBooks.ts @@ -11,7 +11,9 @@ export function useBooks() { const books = getChildrenById(routes, Books_ID); // the latest books are displayed first - books.sort((a, b) => new Date(b.meta!.date).getTime() - new Date(a.meta!.date).getTime()); + books + .filter((book) => !book.meta!.draft) + .sort((a, b) => new Date(b.meta!.date).getTime() - new Date(a.meta!.date).getTime()); return books; }, [routes]); diff --git a/src/viewer/hooks/useExamples.ts b/src/viewer/hooks/useExamples.ts index 6587cc6..48cb221 100644 --- a/src/viewer/hooks/useExamples.ts +++ b/src/viewer/hooks/useExamples.ts @@ -11,7 +11,9 @@ export function useExamples() { const examples = getChildrenById(routes, Examples_ID); // the latest examples are displayed first - examples.sort((a, b) => new Date(b.meta!.date).getTime() - new Date(a.meta!.date).getTime()); + examples + .filter((example) => !example.meta!.draft) + .sort((a, b) => new Date(b.meta!.date).getTime() - new Date(a.meta!.date).getTime()); return examples; }, [routes]);