import icons from '../../config/icons.ts'
import { currentLocale } from '../../runtime/i18n.ts'
import { isRecord, type ChromeOptions } from '../../types.ts'
import { serverOption } from '../../utilities/features.ts'
import { escapeHtml } from '../../utilities/html.ts'
import { normalizeSiteName } from '../../utilities/page.ts'
import { toText } from '../../utilities/string.ts'
import { renderMenuList, renderTreeNav } from './navigation.ts'
function attr(value: unknown): string {
return escapeHtml(value)
}
function renderHeaderMenu(options: ChromeOptions): string {
if (!options.menuEnabled) return ''
return ``
}
function renderSearch(searchEnabled: boolean): string {
return searchEnabled
? ''
: ''
}
function renderLocale(i18nEnabled: boolean): string {
return i18nEnabled
? ''
: ''
}
function renderTheme(themeEnabled: boolean): string {
return themeEnabled
? ''
: ''
}
function renderAuth(authEnabled: boolean): string {
return authEnabled
? ''
: ''
}
function renderMenuButton(menuEnabled: boolean): string {
return menuEnabled
? ''
: ''
}
function renderSidebarButton(sidebarEnabled: boolean): string {
return sidebarEnabled
? ''
: ''
}
function renderTocButton(tocEnabled: boolean): string {
return tocEnabled
? ''
: ''
}
export function renderHeaderDocNav(options: ChromeOptions): string {
const sidebarButton = renderSidebarButton(options.sidebarEnabled)
const tocButton = renderTocButton(options.tocEnabled)
if (!sidebarButton && !tocButton) return ''
return `
`
}
function renderHeader(options: ChromeOptions): string {
const siteName = normalizeSiteName(options.config)
const headerMenu = renderHeaderMenu(options)
const menuButton = renderMenuButton(options.menuEnabled)
const search = renderSearch(options.searchEnabled)
const socialList = renderSocialList(options.config)
const locale = renderLocale(options.i18nEnabled)
const theme = renderTheme(options.themeEnabled)
const auth = renderAuth(options.authEnabled)
return ``
}
function renderMobileMenuContent(options: ChromeOptions): string {
if (!options.menuEnabled) return ''
const locale = currentLocale(options.languages, options.page)
return `
`
}
export function renderHeaderTemplates(options: ChromeOptions): string {
const header = renderHeader(options)
const mobileMenuContent = renderMobileMenuContent(options)
return `${header}
${mobileMenuContent}`
}
function renderIcon(name: string): string {
const content = icons[name as keyof typeof icons]
if (!content) return ''
return ``
}
export function renderFooterInfo(config = {}): string {
const siteName = normalizeSiteName(config)
const year = new Date().getFullYear()
const siteUrl = toText((config as { siteUrl?: unknown }).siteUrl)
const icpConfig = serverOption(config, 'icp')
return ``
}
export function renderSocialList(config = {}): string {
const socialValue = serverOption(config, 'social')
const socialConfig = isRecord(socialValue) ? socialValue : {}
const social = Object.entries(socialConfig)
.map(([name, href]) => {
const url = toText(href).trim()
if (!url) return ''
return `${renderIcon(name)}`
})
.filter(Boolean)
.join('')
return social ? `${social}
` : ''
}