Files
FixIt/assets/js/custom.ts.example
Cell 4b3f33f35a refactor(assets): improve custom script examples and SCSS configuration
- Add custom.js.example alongside custom.ts.example
- Update examples to use window.fixit instead of importing from theme source
- Add "Build" true for custom.ts in assets pipeline so esbuild compiles it
- Make code_font_family configurable via [params.appearance] in hugo.toml
- Standardize SCSS header comments: // → ///, remove Chinese text
- Add documented examples in custom.scss: fonts, page width, admonitions, task lists
2026-06-22 15:35:41 +08:00

50 lines
1.3 KiB
Plaintext

/**
* Custom TypeScript for FixIt site.
*
* Copy this file to your project's assets/js/ directory
* and rename it to custom.ts to activate it.
* Access the FixIt public API via `window.fixit`.
* @see https://fixit.lruihao.cn
*/
const { fixit } = window as any
class CustomScript {
constructor() {
this.init()
}
init() {
console.log('hello from custom.ts!')
console.log('FixIt API:', fixit)
// Top-level properties
console.log('version:', fixit.version)
console.log('themeMode:', fixit.themeMode)
console.log('isDark:', fixit.isDark)
console.log('config:', fixit.config)
// Theme control
// fixit.setThemeMode('dark')
// fixit.setThemeMode('auto', true) // persist to localStorage
// Mask overlay (via core module)
// fixit.core.registerMaskOverlay('my-overlay', {
// isActive: () => boolean,
// onOpen: () => void,
// onClose: () => void,
// })
// Typed event bus
fixit.eventBus.on('fixit:switch-theme', ({ detail }: { detail: { mode: string, isDark: boolean, isChanged: boolean } }) => {
console.log('Theme switched:', detail.mode, 'isDark:', detail.isDark, 'isChanged:', detail.isChanged)
})
return this
}
}
document.addEventListener('DOMContentLoaded', () => {
void new CustomScript()
})