Skip to content

Commit

Permalink
chore: service worker config change
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanyxh committed Sep 25, 2024
1 parent c342f70 commit a68293b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 3 deletions.
9 changes: 9 additions & 0 deletions helpers/generateSw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions helpers/vite-generateSw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface Meta {
description: string;
imageUrl: string;
book?: boolean;
draft?: boolean;
}

/** user route */
Expand Down
6 changes: 6 additions & 0 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
type IFileDataType = 'text' | 'dataurl' | 'binrary';

/**
*
* @description read file
* @param file
* @param type
*/
export function readFile(file: File, type: 'text'): Promise<string>;
export function readFile(file: File, type: 'dataurl'): Promise<string>;
export function readFile(file: File, type: 'binrary'): Promise<ArrayBuffer>;
Expand Down
4 changes: 3 additions & 1 deletion src/viewer/hooks/useArticles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 3 additions & 1 deletion src/viewer/hooks/useBooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 3 additions & 1 deletion src/viewer/hooks/useExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit a68293b

Please sign in to comment.