Add demo library (books from Feedbooks)

This commit is contained in:
chrox
2024-12-11 18:57:39 +01:00
parent 9dd7e6de5e
commit 3f4a274412
11 changed files with 135 additions and 17 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
import { EXTS } from '@/libs/document';
import { Book, BookConfig } from '@/types/book';
import { makeSafeFilename } from './misc';
import { getUserLang, makeSafeFilename } from './misc';
export const getDir = (book: Book) => {
return `${book.hash}`;
@@ -37,7 +37,7 @@ interface Contributor {
name: LanguageMap;
}
const userLang = navigator?.language || 'en';
const userLang = getUserLang();
const formatLanguageMap = (x: string | LanguageMap): string => {
if (!x) return '';
+11
View File
@@ -23,6 +23,8 @@ export const makeSafeFilename = (filename: string, replacement = '_') => {
return safeName.trim();
};
export const getUserLang = () => navigator?.language.split('-')[0] || 'en';
export const getOSPlatform = () => {
const userAgent = navigator.userAgent.toLowerCase();
@@ -34,3 +36,12 @@ export const getOSPlatform = () => {
return '';
};
export const isValidURL = (url: string, allowedSchemes: string[] = ['http', 'https']) => {
try {
const { protocol } = new URL(url);
return allowedSchemes.some((scheme) => `${scheme}:` === protocol);
} catch {
return false;
}
};