refactor: fix typescript errors

This commit is contained in:
Caesar Schinas 2023-08-08 12:06:56 +01:00
parent 82d95864fb
commit 849190f8a7
No known key found for this signature in database
GPG key ID: AE9108461BEA5ACF
10 changed files with 41 additions and 40 deletions

View file

@ -9,5 +9,6 @@
"prettier.documentSelectors": ["**/*.astro"],
"[astro]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
},
"typescript.tsdk": "node_modules/typescript/lib"
}

View file

@ -8,25 +8,29 @@ import sitemap from '@astrojs/sitemap';
import image from '@astrojs/image';
import mdx from '@astrojs/mdx';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import type { Options as rehypeAutolinkOptions } from 'rehype-autolink-headings';
import rehypeSlug from 'rehype-slug';
import { toString } from 'hast-util-to-string';
import { SITE } from './src/config.mjs';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
function getAutolink(el) {
const heading = el.children.length > 0 ? el.children[0].value : 'this';
const autolinkOptions: rehypeAutolinkOptions = {
behavior: 'append',
properties: {},
content: (heading) => {
return {
type: 'element',
tagName: 'span',
properties: {
ariaLabel: `Permalink to ${heading}” section`,
ariaLabel: `Permalink to ${toString(heading)}” section`,
className: ['icon', 'icon-link'],
},
children: [],
};
}
},
};
export default defineConfig({
site: SITE.origin,
@ -38,9 +42,7 @@ export default defineConfig({
integrations: [
tailwind({
config: {
applyBaseStyles: false,
},
}),
sitemap(),
image({
@ -50,17 +52,7 @@ export default defineConfig({
],
markdown: {
rehypePlugins: [
rehypeSlug,
[
rehypeAutolinkHeadings,
{
behavior: 'append',
properties: {},
content: getAutolink,
},
],
],
rehypePlugins: [rehypeSlug, [rehypeAutolinkHeadings, autolinkOptions]],
},
vite: {

View file

@ -13,7 +13,7 @@ const { src: defaultImage } = await getImage({
src: ogPreviewImage,
width: 1200,
height: 628,
alt: undefined,
alt: '',
});
const {

View file

@ -17,7 +17,7 @@ const {
<script>
function darkRuleOverrider() {
// Gather the dark-mode rules (stylesheets must have already loaded)
const darkRules = [];
const darkRules: CSSMediaRule[] = [];
for (const stylesheet of document.styleSheets) {
for (const rule of stylesheet.cssRules) {
if (rule instanceof CSSMediaRule && rule.media?.mediaText === '(prefers-color-scheme: dark)') {

View file

@ -3,7 +3,7 @@ import { Icon } from 'astro-icon';
const { license, sourceURL, originURL } = Astro.props;
let license_url: string;
let license_url = '';
if (license != null) {
license_url = 'https://spdx.org/licenses/' + license + '.html';
}

View file

@ -1,4 +1,10 @@
---
import type { MarkdownHeading } from 'astro';
interface Props {
headings: MarkdownHeading[];
title: string;
}
const { headings, title } = Astro.props;
---

View file

@ -1,4 +1,5 @@
---
import type { GetStaticPathsOptions } from 'astro';
import { getCollection } from 'astro:content';
import { Icon } from 'astro-icon';
@ -11,7 +12,7 @@ import Pagination from '~/components/atoms/Pagination.astro';
import { getCanonical, getPermalink, BLOG_BASE } from '~/utils/permalinks';
export async function getStaticPaths({ paginate }) {
export async function getStaticPaths({ paginate }: GetStaticPathsOptions) {
if (BLOG?.disabled || BLOG?.blog?.disabled) return [];
const posts = await getCollection('blog');

View file

@ -1,4 +1,5 @@
---
import type { GetStaticPathsOptions } from 'astro';
import { getCollection } from 'astro:content';
import { SITE, BLOG } from '~/config.mjs';
@ -9,7 +10,7 @@ import Pagination from '~/components/atoms/Pagination.astro';
import { getCanonical, getPermalink, cleanSlug, TAG_BASE } from '~/utils/permalinks';
export async function getStaticPaths({ paginate }) {
export async function getStaticPaths({ paginate }: GetStaticPathsOptions) {
if (BLOG?.disabled || BLOG?.tag?.disabled) return [];
const allPosts = await getCollection('blog');

View file

@ -6,14 +6,14 @@ import Layout from '~/layouts/PageLayout.astro';
import { getRelativeLink } from '~/utils/permalinks';
const latest = await getLatestRelease();
const latest_v = latest.tag_name.replace(/^v/, '');
const latest_dl = latest.html_url.replace('/tag/', '/download/');
const latest_v = latest.tag_name?.replace(/^v/, '');
const latest_dl = latest.html_url?.replace('/tag/', '/download/');
const asset_bin = latest.assets?.find((asset: Attachment) => asset?.name === `forgejo-${latest_v}-linux-amd64`);
const asset_sig = latest.assets?.find((asset: Attachment) => asset?.name === `forgejo-${latest_v}-linux-amd64.asc`);
const asset_bin_lnk = [latest_dl, asset_bin.name].join('/');
const asset_sig_lnk = [latest_dl, asset_sig.name].join('/');
const asset_bin_lnk = [latest_dl, asset_bin?.name].join('/');
const asset_sig_lnk = [latest_dl, asset_sig?.name].join('/');
---
<Layout title="Download">
@ -41,7 +41,7 @@ const asset_sig_lnk = [latest_dl, asset_sig.name].join('/');
</p>
<pre>
wget {asset_bin_lnk}
chmod +x {asset_bin.name}
chmod +x {asset_bin?.name}
</pre>
<h3>Verify GPG signature</h3>
<p>
@ -56,7 +56,7 @@ chmod +x {asset_bin.name}
<pre>
gpg --keyserver keys.openpgp.org --recv EB114F5E6C0DC2BCDD183550A4B61A2DC5923710
wget {asset_sig_lnk}
gpg --verify {asset_sig.name} {asset_bin.name}
gpg --verify {asset_sig?.name} {asset_bin?.name}
</pre>
<h2 id="container-image">Container image</h2>

View file

@ -1,5 +1,5 @@
{
"extends": "astro/tsconfigs/base",
"extends": "astro/tsconfigs/strict",
"compilerOptions": {
"types": ["astro/client"],
"allowJs": true,