Skip to content

Commit

Permalink
Eslint and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Petry committed Sep 19, 2023
1 parent 6450a14 commit f76ae6e
Show file tree
Hide file tree
Showing 45 changed files with 149 additions and 145 deletions.
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

version: 2
updates:
- package-ecosystem: 'npm' # See documentation for possible values
directory: '/' # Location of package manifests
- package-ecosystem: npm # See documentation for possible values
directory: / # Location of package manifests
schedule:
interval: 'weekly'
interval: weekly
8 changes: 4 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: 'CodeQL'
name: CodeQL

on:
push:
branches: ['main']
branches: [main]
pull_request:
# The branches below must be a subset of the branches above
branches: ['main']
branches: [main]
schedule:
- cron: '21 9 * * 6'

Expand All @@ -33,7 +33,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: ['javascript']
language: [javascript]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
Expand Down
14 changes: 0 additions & 14 deletions .prettierignore

This file was deleted.

16 changes: 0 additions & 16 deletions .prettierrc

This file was deleted.

7 changes: 4 additions & 3 deletions app/router.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const RouteOptions: RouterConfig = {
// If history back
if (savedPosition) {
// Handle Suspense resolution
return new Promise(resolve => {
return new Promise((resolve) => {
nuxtApp.hooks.hookOnce('page:finish', () => {
setTimeout(() => resolve(savedPosition), 50)
})
Expand All @@ -18,11 +18,12 @@ const RouteOptions: RouterConfig = {
if (to.hash) {
setTimeout(() => {
let heading = document.querySelector(
`[id="${to.hash.replace('#', '')}"]`
`[id="${to.hash.replace('#', '')}"]`,
) as any
if (!heading)
heading = document.querySelector(`[href$="${to.hash}"]`) as any
if (!heading) return
if (!heading)
return
return window.scrollTo({
top: heading.offsetTop,
behavior: 'smooth',
Expand Down
8 changes: 4 additions & 4 deletions app/runtime/nitro/content-post-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const mdPlugins = [

const miscPlugins = [Projects]

export const ContentPostProcess: NitroAppPlugin = nitroApp => {
nitroApp.hooks.hook('content:file:afterParse', async content => {
if (content._extension === 'md') {
export const ContentPostProcess: NitroAppPlugin = (nitroApp) => {
nitroApp.hooks.hook('content:file:afterParse', async (content) => {
if (content._extension === 'md')
for (const plugin of mdPlugins) content = await plugin(content)
}

for (const plugin of miscPlugins) content = await plugin(content)
})
}
Expand Down
6 changes: 3 additions & 3 deletions app/runtime/nitro/content/code-file-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ export function CodeFilename(content: ParsedContent) {
tag: 'CodeBlock',
props: {
'data-language': node.props.language,
class: [
'class': [
'code-block',
node.props.filename ? 'code-block--with-filename' : '',
].join(' '),
},
children,
},
]
],
)
}
},
)
return content
}
2 changes: 1 addition & 1 deletion app/runtime/nitro/content/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function Links(content: ParsedContent) {
// })
// }
}
}
},
)
return content
}
3 changes: 2 additions & 1 deletion app/runtime/nitro/content/meta-normaliser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { ParsedContent } from '~/types'

export function MetaNormaliser(content: ParsedContent) {
// turn the content _path to a real path
if (content._path?.startsWith('/blog/')) content.layout = 'post'
if (content._path?.startsWith('/blog/'))
content.layout = 'post'

content.schemaOrg = content.schemaOrg || {}
// if no published at / modified at is set we can infer from the storage meta
Expand Down
13 changes: 7 additions & 6 deletions app/runtime/nitro/content/nuxt-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,31 @@ export function NuxtImage(content: ParsedContent) {
(node: MarkdownNode, index, parent: MarkdownNode) => {
parent.children.splice(index, 1, ...node.children)
return index
}
},
)

visit(
content.body,
(node: any) => node?.tag === 'img',
node => {
(node) => {
// image is a simple wrapper around NuxtImg
node.tag = 'Image'
const intKeys = ['height', 'width', 'max-height']
intKeys.forEach(k => {
if (node.props[k]) node.props[k] = Number.parseInt(node.props[k])
intKeys.forEach((k) => {
if (node.props[k])
node.props[k] = Number.parseInt(node.props[k])
})
if (node.props.height && node.props.width) {
node.props = {
...node.props,
...computeSizes(
node.props.width,
node.props.height,
node.props['max-height']
node.props['max-height'],
),
}
}
}
},
)
return content
}
5 changes: 3 additions & 2 deletions app/runtime/nitro/content/og-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import type { ParsedContent } from '~/types'

export function OgImage(content: ParsedContent) {
content.ogImage = content.ogImage || {}
if (content.ogImage.image) return content
if (content.ogImage.image)
return content
// get first img
visit(
content.body,
(node: MarkdownNode) => node?.tag === 'img',
(node: MarkdownNode) => {
if (node?.props?.src && !content.ogImage.image)
content.ogImage = { image: node.props.src }
}
},
)
return content
}
9 changes: 6 additions & 3 deletions app/runtime/nitro/content/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ import { $fetch } from 'ofetch'
import type { ParsedContent } from '~/types'

export async function Projects(content: ParsedContent) {
if (content._file !== '_projects.json') return content

if (content._file !== '_projects.json')
return content
for (const ecosystem of content.body) {
for (const project of ecosystem.projects) {
try {
const { repo } = await $fetch(`https://ungh.cc/repos/${project.repo}`)
project.stars = repo.stars
project.description = repo.description
project.updatedAt = repo.updatedAt
} catch (e) {}
}
catch (e) {
console.error('Cant fetch following Repo', project.repo)
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/runtime/nitro/content/read-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export function ReadTime(content: ParsedContent) {
// check the node itself and children for text nodes
...[...node.children, node]
.filter(n => n.type === 'text')
.map(n => n.value.trim())
.map(n => n.value.trim()),
)
}
},
)
content.readingMins = calculateReadingMins(textNodes.join(' '))
return content
Expand Down
22 changes: 13 additions & 9 deletions app/runtime/nitro/util/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,25 @@ interface LoadIconResponse {
export const iconCollections = collections.sort((a, b) => b.length - a.length)

export function tagIsIcon(tag: string) {
return !!iconCollections.find(i => {
if (!tag || !tag.startsWith('i-')) return false
return !!iconCollections.find((i) => {
if (!tag || !tag.startsWith('i-'))
return false

return tag.substring(2).startsWith(`${i}-`)
})
}

export function normaliseSvgAttrs(svg: string, icon: string) {
// svg is possibly empty for an invalid icon
if (!svg) return false
if (!svg)
return false
const $ = cheerio.load(svg)
const options: Record<string, any> = {
...$('svg').attr(),
// presume all icons are decorative
'aria-hidden': true,
title: icon,
innerHTML: $('svg').html(),
'title': icon,
'innerHTML': $('svg').html(),
}
return options
}
Expand All @@ -153,21 +155,23 @@ export async function loadIconForTag(tag: string) {
if (tag.startsWith('i-emojione-v-1'))
tag = tag.replace('i-emojione-v-1', 'i-emojione-v1')

if (iconCache[tag]) return iconCache[tag]
if (iconCache[tag])
return iconCache[tag]

const collection = iconCollections.find(i =>
tag.substring(2).startsWith(`${i}-`)
tag.substring(2).startsWith(`${i}-`),
)
const icon = tag.substring(2).slice(collection.length + 1)
const svg = await loadNodeIcon(collection, icon, {
addXmlNs: false,
autoInstall: true,
})

if (!svg)
if (!svg) {
console.warn(
`Failed to find icon \`${icon}\` in collection \`${collection}\`.`
`Failed to find icon \`${icon}\` in collection \`${collection}\`.`,
)
}

const res: LoadIconResponse = {
svgRaw: svg,
Expand Down
2 changes: 1 addition & 1 deletion app/runtime/nitro/util/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const defaultAspectRatio = 16 / 9
export function computeSizes(
width: number,
height: number,
maxHeight?: number
maxHeight?: number,
) {
maxHeight = maxHeight || (height > MaxHeight ? MaxHeight : height)
// figure out aspect ratio
Expand Down
5 changes: 3 additions & 2 deletions components/ColorModeSwitch.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script setup lang="ts">
const colorMode = useColorMode()
const toggleMode = () =>
colorMode.value === 'light'
function toggleMode() {
return colorMode.value === 'light'
? (colorMode.preference = 'dark')
: (colorMode.preference = 'light')
}
</script>

<template>
Expand Down
8 changes: 4 additions & 4 deletions components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ const { data: nav } = await useHeaderNav()
:class="
slot?.isActive
? [
'sm:bg-green-50',
'text-green-800',
'dark:(sm:bg-green-800/10 text-green-50)',
]
'sm:bg-green-50',
'text-green-800',
'dark:(sm:bg-green-800/10 text-green-50)',
]
: []
"
class="md:(px-3 py-2) px-1 py-1 rounded"
Expand Down
4 changes: 3 additions & 1 deletion components/NewsletterAlert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const { prev } = useContent()
class="max-w-xl relative border transition rounded-xl overflow-hidden dark:border-gray-500"
>
<div class="p-4">
<h3 class="font-semibold mb-3">Regularly newsletter</h3>
<h3 class="font-semibold mb-3">
Regularly newsletter
</h3>
<div class="text-sm mt-1 text-gray-500 dark:text-gray-300 prose">
<p class="mb-2">
At least each quarter I try to send an update of my journey working on
Expand Down
10 changes: 5 additions & 5 deletions components/OgImage/Newsletter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ const siteName = computed(() => {
})
const siteLogo = computed(() => {
return (
props.siteLogo ||
siteConfig.logo ||
'https://nuxt.com/assets/design-kit/logo/full-logo-green-light.png'
props.siteLogo
|| siteConfig.logo
|| 'https://nuxt.com/assets/design-kit/logo/full-logo-green-light.png'
)
})
</script>
Expand Down Expand Up @@ -167,7 +167,7 @@ const siteLogo = computed(() => {
:src="siteLogo"
height="50"
class="rounded mr-5"
/>
>
<div style="font-size: 30px" class="font-bold mt-2">
{{ siteName }}
</div>
Expand All @@ -182,7 +182,7 @@ const siteLogo = computed(() => {
width="630"
style="object-fit: cover"
class="rounded-xl max-w-full"
/>
>
</div>
</div>
</template>
6 changes: 3 additions & 3 deletions components/OgImage/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const backgroundFlareTwoAttrs = {
const siteConfig = useSiteConfig()
const siteLogo = computed(() => {
return (
siteConfig.logo ||
'https://nuxt.com/assets/design-kit/logo/full-logo-green-light.png'
siteConfig.logo
|| 'https://nuxt.com/assets/design-kit/logo/full-logo-green-light.png'
)
})
</script>
Expand All @@ -55,6 +55,6 @@ const siteLogo = computed(() => {
<div v-bind="backgroundFlareAttrs" />
<div v-bind="backgroundFlareTwoAttrs" />
<div class="w-full flex items-center justify-center h-full flex-row z-10">
<img v-if="siteLogo" :src="siteLogo" height="200" class="rounded mr-5" />
<img v-if="siteLogo" :src="siteLogo" height="200" class="rounded mr-5">
</div>
</template>
Loading

0 comments on commit f76ae6e

Please sign in to comment.