Skip to content

Commit 555b76e

Browse files
committed
fix the astro ts warnings
1 parent ca68b5e commit 555b76e

File tree

13 files changed

+35
-29
lines changed

13 files changed

+35
-29
lines changed

scripts/fill-category-paths.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env node
2-
const fs = require("fs").promises;
3-
const path = require("path");
2+
import fs from "fs/promises";
3+
import path from "path";
4+
import { fileURLToPath } from "url";
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
48

59
function slugify(str) {
610
return String(str)

src/components/bases/head.astro

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import "@fontsource-variable/source-serif-4";
77
import { ClientRouter } from "astro:transitions";
88
import { SITE } from "@/lib/config";
99
import type { ArticleMeta, Meta } from "@/lib/types";
10-
import { GOOGLE_CONFIG, getGATagConfig, getGTMContainerId, hasGoogleAnalytics, hasGoogleTagManager, hasGoogleAdSense } from "@/utils/google-config";
10+
import { GOOGLE_CONFIG, hasGoogleAnalytics, hasGoogleTagManager, hasGoogleAdSense } from "@/utils/google-config";
1111
1212
type Props = {
1313
meta: Meta | ArticleMeta;
@@ -41,7 +41,7 @@ const OGImage = new URL(meta.ogImage, Astro.url).href;
4141

4242
<!-- Google AdSense -->
4343
{hasGoogleAdSense() && (
44-
<script async src={`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${GOOGLE_CONFIG.ADSENSE_CLIENT_ID}`}
44+
<script is:inline async src={`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${GOOGLE_CONFIG.ADSENSE_CLIENT_ID}`}
4545
crossorigin="anonymous"></script>
4646
)}
4747

@@ -213,7 +213,7 @@ const OGImage = new URL(meta.ogImage, Astro.url).href;
213213
))}
214214

215215
<!-- Article structured data -->
216-
<script type="application/ld+json">
216+
<script is:inline type="application/ld+json">
217217
{JSON.stringify({
218218
'@context': 'https://schema.org',
219219
'@type': 'Article',
@@ -248,7 +248,7 @@ const OGImage = new URL(meta.ogImage, Astro.url).href;
248248
</script>
249249

250250
<!-- Breadcrumb structured data -->
251-
<script type="application/ld+json">
251+
<script is:inline type="application/ld+json">
252252
{JSON.stringify({
253253
'@context': 'https://schema.org',
254254
'@type': 'BreadcrumbList',
@@ -280,7 +280,7 @@ const OGImage = new URL(meta.ogImage, Astro.url).href;
280280

281281
{
282282
!isArticleMeta(meta) && meta.metaTitle ? (
283-
<script type="application/ld+json">
283+
<script is:inline type="application/ld+json">
284284
{JSON.stringify({
285285
'@context': 'https://schema.org',
286286
'@type': 'WebSite',
@@ -292,14 +292,14 @@ const OGImage = new URL(meta.ogImage, Astro.url).href;
292292
name: SITE.title,
293293
logo: {
294294
'@type': 'ImageObject',
295-
url: new URL('/favicon.png', Astro.site).href,
295+
url: new URL('/favicon.png', SITE.url).href,
296296
},
297297
},
298298
potentialAction: {
299299
'@type': 'SearchAction',
300300
target: {
301301
'@type': 'EntryPoint',
302-
urlTemplate: new URL('/search?q={search_term_string}', Astro.site).href,
302+
urlTemplate: new URL('/search?q={search_term_string}', SITE.url).href,
303303
},
304304
'query-input': 'required name=search_term_string',
305305
},

src/components/bases/script.astro

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,21 @@
8989
textArea.select();
9090

9191
try {
92-
document.execCommand("copy");
93-
console.log("Fallback: Text copied to clipboard");
92+
// Use modern Clipboard API if available, fallback to execCommand
93+
if (navigator.clipboard && navigator.clipboard.writeText) {
94+
navigator.clipboard
95+
.writeText(text)
96+
.then(() => {
97+
console.log("Fallback: Text copied to clipboard");
98+
})
99+
.catch((err) => {
100+
console.error("Fallback: Unable to copy text to clipboard", err);
101+
});
102+
} else {
103+
console.warn(
104+
"Clipboard API not available and execCommand is deprecated"
105+
);
106+
}
94107
} catch (err) {
95108
console.error("Fallback: Unable to copy text to clipboard", err);
96109
}

src/components/elements/giscus.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const lang = env.PUBLIC_GISCUS_LANG || "en";
2222
>
2323
<h2 class="text-lg font-semibold mb-3">Comments</h2>
2424
<script
25+
is:inline
2526
src="https://giscus.app/client.js"
2627
data-repo={repo}
2728
data-repo-id={repoId}

src/components/elements/toc.astro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ const editUrl = `${SITE.github}/edit/main/${articleContentFilePath(article)}`;
107107
let candidate = null;
108108
entries.forEach((entry) => {
109109
if (entry.isIntersecting) {
110-
const id = entry.target.id;
111110
// Prefer the entry closest to the top
112111
if (
113112
!candidate ||

src/components/shared/cookie-consent.astro

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@
246246

247247
// Show customize options
248248
const customizeBtn = document.getElementById("customize-cookies");
249-
const arrowIcon = document.getElementById("customize-arrow");
250249
if (customizeBtn) {
251250
customizeBtn.addEventListener("click", () => {
252251
const isHidden = this.optionsPanel.classList.contains("hidden");
@@ -300,12 +299,6 @@
300299
const analyticsCheckbox = document.getElementById(
301300
"analytics-cookies"
302301
) as HTMLInputElement;
303-
const advertisingCheckbox = document.getElementById(
304-
"advertising-cookies"
305-
) as HTMLInputElement;
306-
const functionalCheckbox = document.getElementById(
307-
"functional-cookies"
308-
) as HTMLInputElement;
309302
const personalizationCheckbox = document.getElementById(
310303
"personalization-cookies"
311304
) as HTMLInputElement;

src/lib/utils/getMeta.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { render, type CollectionEntry } from "astro:content";
22
import { authorsHandler } from "@/lib/handlers/authors";
3-
import defaultImage from "@/assets/images/default-image.jpg";
43
import type { ArticleMeta, Meta } from "@/lib/types";
54
import { capitalizeFirstLetter } from "@/lib/utils/letter";
65
import { normalizeDate } from "@/lib/utils/date";

src/lib/utils/remarks.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { execSync } from "node:child_process";
2-
import { statSync } from "node:fs";
32
import getReadingTime from "reading-time";
43
import { toString as ConvertToString } from "mdast-util-to-string";
54

src/pages/articles/[id].astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
// Legacy route removed. Redirecting to homepage.
33
export const getStaticPaths = () => [];
4-
const { redirect } = Astro;
5-
return redirect("/articles");
64
---
5+
6+
<meta http-equiv="refresh" content="0;url=/articles" />

src/pages/articles/[year]/[month]/[day]/[slug].astro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import BaseLayout from "@/layouts/base.astro";
44
import ContentLayout from "@/layouts/content.astro";
55
import ArticleHeader from "../../../_components/article-header.astro";
66
import Giscus from "@/components/elements/giscus.astro";
7-
import Toc from "@/components/elements/toc.astro";
87
import NewsCard from "@/components/cards/newsCard.astro";
98
import { SITE } from "@/lib/config";
109

0 commit comments

Comments
 (0)