Refactors fallback fonts into a constant

Moves the list of fallback fonts to a dedicated constant file.
This improves code readability and maintainability by centralizing
this configuration.
This commit is contained in:
AlexKucera committed 2025-09-03 19:31:19 +02:00
1 parent ccc0e5aec6
commit 5fc8e348f4
2 files changed
+43 -26

No files matched your search

+3 -26
View File
@@ -20,6 +20,7 @@ import {
} from 'obsidian';
import { obsidianTypstPDFExportSettings, DEFAULT_SETTINGS, ExportFormat } from './src/core/settings';
import { FALLBACK_FONTS, PLUGIN_DIRS } from './src/core/constants';
import { PandocTypstConverter } from './src/converters/PandocTypstConverter';
import { ExportConfigModal } from './src/modal/ExportConfigModal';
import { ExportConfig, ExportConfigModalSettings } from './src/modal/types';
@@ -102,19 +103,7 @@ export class obsidianTypstPDFExport extends Plugin {
} catch (error) {
console.error('Failed to cache fonts from typst:', error);
// Create fallback cache file
const fallbackFonts = [
'Times New Roman',
'Arial',
'Helvetica',
'Georgia',
'Courier New',
'Monaco',
'SF Pro Text',
'SF Mono',
'Concourse OT',
'UbuntuMono Nerd Font Mono',
'Source Code Pro'
];
const fallbackFonts = FALLBACK_FONTS;
const cacheData = {
fonts: fallbackFonts,
@@ -152,19 +141,7 @@ export class obsidianTypstPDFExport extends Plugin {
await this.cacheAvailableFonts();
// Return fallback fonts
return [
'Times New Roman',
'Arial',
'Helvetica',
'Georgia',
'Courier New',
'Monaco',
'SF Pro Text',
'SF Mono',
'Concourse OT',
'UbuntuMono Nerd Font Mono',
'Source Code Pro'
];
return [...FALLBACK_FONTS];
}
}
+40
View File
@@ -0,0 +1,40 @@
/**
* Constants used throughout the Obsidian Typst PDF Export plugin
*/
/**
* Fallback fonts used when Typst font detection fails
*/
export const FALLBACK_FONTS = [
'Times New Roman',
'Arial',
'Helvetica',
'Georgia',
'Courier New',
'Monaco',
'SF Pro Text',
'SF Mono',
'Concourse OT',
'UbuntuMono Nerd Font Mono',
'Source Code Pro'
] as const;
/**
* Plugin-specific directory names
*/
export const PLUGIN_DIRS = {
TEMP_IMAGES: 'temp-images',
TEMP_PANDOC: 'temp-pandoc',
FONTS_CACHE: 'fonts-cache.json'
} as const;
/**
* Export-related constants
*/
export const EXPORT_CONSTANTS = {
DEFAULT_TIMEOUT: 120000, // 2 minutes
NOTICE_DURATION: {
SHORT: 5000,
LONG: 12000
}
} as const;