chore: update comments for consistency, improve code readability and structure

This commit is contained in:
radishzzz 2025-03-22 22:54:23 +00:00
parent ca45fed0aa
commit fedf4cee1e
38 changed files with 46 additions and 60 deletions

View file

@ -16,10 +16,8 @@ const isTag = isTagPage(currentPath)
// Check if there are other languages to switch
const showLanguageSwitcher = moreLocales.length > 0
// Check if only the supported language switch list is used
const useSupportedLangs = isPost || (isTag && supportedLangs.length > 0)
// Choose a language switch list according to the page type
const nextUrl = useSupportedLangs
? getNextSupportedLangPath(currentPath, supportedLangs) // Switch between supported languages
@ -33,7 +31,7 @@ const nextUrl = useSupportedLangs
'lg:(fixed w-14rem top-auto bottom-47 right-[max(5.625rem,calc(50vw-34.375rem))])',
]}
>
<!-- Language switcher -->
<!-- Language Switcher -->
{showLanguageSwitcher && (
<a
href={nextUrl}
@ -52,7 +50,7 @@ const nextUrl = useSupportedLangs
</a>
)}
<!-- Theme toggle -->
<!-- Theme Toggle -->
<button
aria-label="Switch light/dark theme"
class="button-theme-toggle aspect-square w-4.2 c-secondary active:scale-90 hover:c-primary"
@ -68,7 +66,7 @@ const nextUrl = useSupportedLangs
</button>
</div>
<!-- Theme toggle >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
<!-- Theme Toggle Script >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
<script is:inline define:vars={{ lightMode, darkMode }}>
// Update theme
function updateTheme() {

View file

@ -2,13 +2,11 @@
import { defaultLocale, themeConfig } from '@/config'
import { walineLocaleMap } from '@/i18n/config'
// Theme color configuration
const {
light: { primary: lightPrimary, secondary: lightSecondary, background: lightBackground },
dark: { primary: darkPrimary, secondary: darkSecondary, background: darkBackground },
} = themeConfig.color
// Waline configuration
const {
serverURL = '',
emoji = [],
@ -27,7 +25,7 @@ function getWalineLang(currentPath: string, defaultLocale: string): string {
return walineLocaleMap[lang as keyof typeof walineLocaleMap]
}
// Get Waline language and generate configuration
// Get Waline language and generate configuration json
const walineLang = getWalineLang(Astro.url.pathname, defaultLocale)
const walineConfigJson = JSON.stringify({
serverURL,
@ -71,7 +69,7 @@ initWaline()
document.addEventListener('astro:after-swap', initWaline)
</script>
<!-- Custom css styles >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
<!-- Custom CSS Styles >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
<style is:global>
#waline .wl-login-info {
--at-apply: 'mt-0 mr-3'
@ -177,8 +175,8 @@ document.addEventListener('astro:after-swap', initWaline)
}
</style>
<!-- Official css variables >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
<!-- Docs: https://waline.js.org/reference/client/style.html -->
<!-- Official CSS Variables >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
<!-- https://waline.js.org/reference/client/style.html -->
<style
define:vars={{
lightPrimary,

View file

@ -23,6 +23,7 @@ const enableComments = themeConfig.comment?.enabled ?? false
const walineURL = themeConfig.comment?.waline?.serverURL || ''
const showWaline = enableComments && walineURL.trim() !== ''
---
<!-- {showDisqus && <Disqus />} -->
<!-- {showGiscus && <Giscus />} -->
<!-- {showTwikoo && <Twikoo />} -->

View file

@ -10,7 +10,7 @@ const year = Number(startYear) === currentYear
? startYear
: `${startYear}-${currentYear}`
// i18n rss path
// i18n RSS Path
const currentLang = getLangFromPath(Astro.url.pathname)
const links = socialLinks.map((link) => {
if (link.name === 'RSS') {

View file

@ -41,7 +41,7 @@ const SubtitleTag = isPost ? 'div' : 'h2'
'font-bold font-title',
]}
>
<!-- Fix text cropping issues during view transition on ios by adding a div tag -->
<!-- Fix text cropping issues during view transition on iOS by adding a div tag -->
<div
class="box-content inline-block pr-1"
transition:name={`site-title-${currentLang}`}

View file

@ -26,6 +26,7 @@ function getPostPath(post: Post) {
return lang && lang !== defaultLocale ? `/${lang}/posts/${postPath}/` : `/posts/${postPath}/`
}
---
<ul>
{posts.map(post => (
<li

View file

@ -14,6 +14,7 @@
</svg>
</button>
<!-- Go Back Script >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
<script>
function setupBackButton() {
document.getElementById('back-button')?.addEventListener('click', () => {
@ -21,6 +22,7 @@ function setupBackButton() {
window.history.back()
}
else {
// Click site title link to trigger view transition when no history
const titleLink = document.getElementById('site-title-link') as HTMLAnchorElement
if (titleLink) {
titleLink.click()