feat: add a spinner when SPA mode is enabled
This commit is contained in:
parent
e7f889f1f8
commit
a321501977
3 changed files with 49 additions and 2 deletions
4
src/components/helper/spa/SPARouter.astro
Normal file
4
src/components/helper/spa/SPARouter.astro
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
import { ClientRouter } from "astro:transitions";
|
||||||
|
---
|
||||||
|
<ClientRouter />
|
||||||
41
src/components/helper/spa/Spinner.astro
Normal file
41
src/components/helper/spa/Spinner.astro
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
---
|
||||||
|
<div id="spinner-container">
|
||||||
|
<div class="spinner"></div>
|
||||||
|
<span>Loading...</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#spinner-container {
|
||||||
|
display: none;
|
||||||
|
gap: 1rem;
|
||||||
|
margin: 1rem 0;
|
||||||
|
}
|
||||||
|
.spinner:after {
|
||||||
|
animation: changeContent .8s linear infinite;
|
||||||
|
display: block;
|
||||||
|
content: "⠋";
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes changeContent {
|
||||||
|
10% { content: "⠙"; }
|
||||||
|
20% { content: "⠹"; }
|
||||||
|
30% { content: "⠸"; }
|
||||||
|
40% { content: "⠼"; }
|
||||||
|
50% { content: "⠴"; }
|
||||||
|
60% { content: "⠦"; }
|
||||||
|
70% { content: "⠧"; }
|
||||||
|
80% { content: "⠇"; }
|
||||||
|
90% { content: "⠏"; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script is:inline>
|
||||||
|
const spinner = document.getElementById("spinner-container");
|
||||||
|
document.addEventListener("astro:before-preparation", () => {
|
||||||
|
spinner.style.display = 'flex';
|
||||||
|
});
|
||||||
|
document.addEventListener("astro:after-preparation", () => {
|
||||||
|
spinner.style.display = 'none';
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
@ -18,8 +18,9 @@ interface Props {
|
||||||
ogImage?: string;
|
ogImage?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
import { ClientRouter } from "astro:transitions";
|
|
||||||
import PoweredBy from "../components/PoweredBy.astro";
|
import PoweredBy from "../components/PoweredBy.astro";
|
||||||
|
import SPARouter from "../components/helper/spa/SPARouter.astro";
|
||||||
|
import Spinner from "../components/helper/spa/Spinner.astro";
|
||||||
const spaEnabled = siteConfig.spa
|
const spaEnabled = siteConfig.spa
|
||||||
|
|
||||||
const noscript = siteConfig.noClientJavaScript
|
const noscript = siteConfig.noClientJavaScript
|
||||||
|
|
@ -47,7 +48,7 @@ const { title = pageTitle, author = siteConfig.defaultAuthor.name,description =
|
||||||
<meta name="generator" content={Astro.generator} />
|
<meta name="generator" content={Astro.generator} />
|
||||||
<Meta title={pageTitle} author={author} description={description} ogImage={ogImage} />
|
<Meta title={pageTitle} author={author} description={description} ogImage={ogImage} />
|
||||||
<title>{pageTitle}</title>
|
<title>{pageTitle}</title>
|
||||||
{spaEnabled && <ClientRouter fallback="animate" />}
|
{spaEnabled && <SPARouter />}
|
||||||
<!--transitional animation is broken in firefox though-->
|
<!--transitional animation is broken in firefox though-->
|
||||||
</head>
|
</head>
|
||||||
<body class="container">
|
<body class="container">
|
||||||
|
|
@ -58,6 +59,7 @@ const { title = pageTitle, author = siteConfig.defaultAuthor.name,description =
|
||||||
</div>
|
</div>
|
||||||
<Navbar />
|
<Navbar />
|
||||||
<Search />
|
<Search />
|
||||||
|
{spaEnabled && <Spinner />}
|
||||||
</header>
|
</header>
|
||||||
<main class="content-box">
|
<main class="content-box">
|
||||||
<slot />
|
<slot />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue