refactor: extract console banner to core/banner.ts

- Create core/banner.ts for styled console version message
- Replace example.com with real domains in link test content
- Update type definitions and core module
This commit is contained in:
Cell
2026-06-17 18:05:25 +08:00
parent 68d9a352c3
commit 01eadc4356
6 changed files with 28 additions and 18 deletions
+8 -8
View File
@@ -26,7 +26,7 @@ These links are rendered by `layouts/_markup/render-link.html` and should always
- Internal anchor link: [Jump to Card Link section](#card-link-shortcode)
- Absolute same-site link: [Test site home](http://demo.fixit.lruihao.cn/test/)
- External HTTP link: [FixIt Repository](https://github.com/hugo-fixit/FixIt)
- Mail link: [Email test](mailto:test@example.com)
- Mail link: [Email test](mailto:test@gmail.com)
- JavaScript link: [JavaScript test](javascript:void(0))
- Tel link: [Phone test](tel:+1234567890)
- File link: [File test](file:///path/to/file.txt)
@@ -34,7 +34,7 @@ These links are rendered by `layouts/_markup/render-link.html` and should always
### Title Attribute (Markdown)
[External link with title](https://example.com "Example Title")
[External link with title](https://google.com "Example Title")
## Link Shortcode (Regular)
@@ -44,13 +44,13 @@ These links are rendered by `layouts/_markup/render-link.html` and should always
{{< link href="/test/units/codeblock-test/" content="Internal shortcode link" class="shortcode-link-test" >}}
{{< link href="https://example.com" content="Custom rel + no noreferrer" rel="ugc" noreferrer=false >}}
{{< link href="https://google.com" content="Custom rel + no noreferrer" rel="ugc" noreferrer=false >}}
{{< link href="/images/fixit.svg" content="Download local file" download="fixit.svg" >}}
### Positional parameters
{{< link "https://example.org" "Positional regular link" "Positional title" >}}
{{< link "https://mozilla.org" "Positional regular link" "Positional title" >}}
## Card Link Shortcode
@@ -72,16 +72,16 @@ These links are rendered by `layouts/_markup/render-link.html` and should always
### Positional card parameters
{{< link "https://example.com" "Positional card link" "" true "fa-solid fa-link" >}}
{{< link "https://google.com" "Positional card link" "" true "fa-solid fa-link" >}}
## Edge Cases
- URL with query string:
[Search query test](https://example.com/search?q=fixit&lang=en)
[Search query test](https://google.com/search?q=fixit&lang=en)
- URL with fragment:
[Fragment test](https://example.com/docs#installation)
[Fragment test](https://google.com/docs#installation)
- Long URL display (card meta should trim protocol automatically):
{{< link href="https://example.com/a/very/long/path/for/testing/card/url/display?foo=bar&baz=qux" content="Long URL card" card=true >}}
{{< link href="https://google.com/a/very/long/path/for/testing/card/url/display?foo=bar&baz=qux" content="Long URL card" card=true >}}
## Manual Verification Checklist
+13
View File
@@ -0,0 +1,13 @@
/**
* Console banner — prints a styled FixIt version message in the browser console.
*/
export function printBanner(version: string) {
const color = '#FF735A'
// eslint-disable-next-line no-console
console.log(
`%c FixIt ${version} %c https://github.com/hugo-fixit %c`,
`background: ${color}; border: 1px solid ${color}; padding: 1px; border-radius: 2px 0 0 2px; color: #fff;`,
`border: 1px solid ${color}; padding: 1px; border-radius: 0 2px 2px 0; color: ${color};`,
'background: transparent;',
)
}
+3 -8
View File
@@ -1,3 +1,4 @@
import { printBanner } from './core/banner'
import { eventBus } from './core/event-bus'
import { CodeModule } from './modules/code'
import { ContentModule } from './modules/content'
@@ -33,6 +34,7 @@ function bootstrap(): void {
// Build window.fixit facade
window.fixit = {
get config() { return core.config },
get version() { return core.version },
get themeMode() { return core.themeMode },
get isDark() { return core.isDark },
get newScrollTop() { return core.newScrollTop },
@@ -69,14 +71,7 @@ function bootstrap(): void {
catch (err) {
console.error(err)
}
const fixitColor = '#FF735A'
// eslint-disable-next-line no-console
console.log(
`%c FixIt ${core.config.version} %c https://github.com/hugo-fixit %c`,
`background: ${fixitColor};border:1px solid ${fixitColor}; padding: 1px; border-radius: 2px 0 0 2px; color: #fff;`,
`border:1px solid ${fixitColor}; padding: 1px; border-radius: 0 2px 2px 0; color: ${fixitColor};`,
'background:transparent;',
)
printBanner(core.version)
}
document.addEventListener('DOMContentLoaded', init, false)
+2
View File
@@ -12,6 +12,7 @@ import { getScrollTop, getThemeMode, isDarkMode } from '../utils'
*/
export class CoreModule implements CoreService {
readonly config: FixItConfig
readonly version: string
themeMode: string
isDark: boolean
newScrollTop: number
@@ -23,6 +24,7 @@ export class CoreModule implements CoreService {
constructor() {
this.config = window.config
this.version = this.config.version
this.themeMode = getThemeMode()
this.isDark = isDarkMode()
this.newScrollTop = getScrollTop()
+1 -2
View File
@@ -9,8 +9,7 @@ export interface MaskOverlayHandler {
/** FixIt theme configuration (typed version of window.config) */
export interface FixItConfig {
version?: string
themeMode?: string
version: string
twemoji?: boolean
search?: SearchConfig
cse?: CSEConfig
+1
View File
@@ -17,6 +17,7 @@ type FixItDocumentEventMap = {
/** Public API exposed on window.fixit. */
export interface FixItPublicAPI {
readonly config: FixItConfig
readonly version: string
readonly themeMode: string
readonly isDark: boolean
readonly newScrollTop: number