Skip to content

Commit

Permalink
fixing a lot of eslint stuff, mainly type any
Browse files Browse the repository at this point in the history
  • Loading branch information
LukaHarambasic committed Dec 29, 2023
1 parent fa44c21 commit 53c4cf8
Show file tree
Hide file tree
Showing 15 changed files with 7,593 additions and 7,557 deletions.
15,030 changes: 7,515 additions & 7,515 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions scripts/fetch-shareable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import { createClient } from '@supabase/supabase-js';

const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_API_KEY);

const { data: shareables, error } = await supabase
.from('record')
.select('*')
.eq('releasable', true);
const { data: shareables } = await supabase.from('record').select('*').eq('releasable', true);

const saveTo = join('..', '..', 'src', 'content', 'shareables');
shareables.forEach((shareable) => {
// TODO check if file already exists and if so skip
// TODO go over dates, maybe adjsut table and also generate dates in same format as others
const { title, description, comment, category, url, updated, created_at } = shareable;
const { title, description, comment, category, url, created_at } = shareable;
const content = `---
title: "${title}"
description: "${description.replace('"', "'")}"
Expand Down
5 changes: 3 additions & 2 deletions src/lib/components/Entries/EntriesSorter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
export let propertiesEnum: SortProperty;
export let propertiesDefault: SortProperty = null;
const properties = enumToArray(propertiesEnum).sort((a: any, b: any) =>
const properties = enumToArray(propertiesEnum).sort((a: SortProperty, b: SortProperty) =>
sortAlphabetical(a.key, b.key)
);
let property: SortProperty = propertiesDefault || 'PUBLISHED';
function onPropertyChange() {
setParam('property', property);
dispatch('propertyChange', property);
}
const directions = enumToArray(SortDirection).sort((a: any, b: any) =>
const directions = enumToArray(SortDirection).sort((a: SortProperty, b: SortProperty) =>
sortAlphabetical(a.key, b.key)
);
let direction: SortDirection = SortDirection.Desc;
Expand Down
9 changes: 5 additions & 4 deletions src/lib/data/posts/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { RawEntry } from '$lib/types/entry';
import { EntryType, PostSortProperty, SortDirection } from '$lib/types/enums';
import type { Post, TocNode } from '$lib/types/post';
import type { Post } from '$lib/types/post';
import { filterByTag, getDate, getTag, sortByDirection } from '$lib/util/entries';
import { getSlug, sortAlphabetical, sortDate } from '$lib/util/helper';

Expand Down Expand Up @@ -28,7 +29,7 @@ export function sortByProperty(a: Post, b: Post, property: PostSortProperty): nu
}
}

export function getPost(entry: any): Post {
export function getPost(entry: RawEntry): Post {
const meta = entry.meta;
const type = EntryType.Post;
const slug = getSlug(meta.title);
Expand All @@ -41,8 +42,8 @@ export function getPost(entry: any): Post {
tags: meta.tags.map((tag: string) => getTag(tag, type)) || [],
published: getDate(meta.published),
updated: getDate(meta.updated),
tldr: meta.tldr,
discussion: meta.discussion,
tldr: meta.tldr || '',
discussion: meta.discussion || '',
toc: entry.toc,
slug,
relativePath,
Expand Down
5 changes: 3 additions & 2 deletions src/lib/data/projects/helper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { RawEntry } from '$lib/types/entry';
import { EntryType, ProjectSortProperty, ProjectStatus, SortDirection } from '$lib/types/enums';
import type { Project } from '$lib/types/project';
import { filterByTag, getDate, getTag, sortByDirection } from '$lib/util/entries';
Expand All @@ -17,7 +18,7 @@ export function filterAndSort(
.sort(() => sortByDirection(sortDirection));
}

export function getProject(entry: any): Project {
export function getProject(entry: RawEntry): Project {
const meta = entry.meta;
const type = EntryType.Project;
const slug = getSlug(meta.title);
Expand All @@ -32,7 +33,7 @@ export function getProject(entry: any): Project {
published: getDate(meta.published),
updated: getDate(meta.updated),
links: meta.links || [],
prio: meta.prio,
prio: meta.prio || 0,
status: meta.status,
slug,
relativePath,
Expand Down
5 changes: 3 additions & 2 deletions src/lib/data/shareable/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Shareable } from '$lib/types/shareable';
import { EntryType, ShareableSortProperty, SortDirection } from '$lib/types/enums';
import { filterByTag, getDate, getTag, sortByDirection } from '$lib/util/entries';
import { getSlug, sortAlphabetical, sortDate } from '$lib/util/helper';
import type { RawEntry } from '$lib/types/entry';

export function filterAndSort(
entries: Shareable[],
Expand All @@ -15,7 +16,7 @@ export function filterAndSort(
.sort(() => sortByDirection(sortDirection));
}

export function getShareable(entry: any): Shareable {
export function getShareable(entry: RawEntry): Shareable {
const meta = entry.meta;
const type = EntryType.Shareable;
const slug = getSlug(meta.title);
Expand All @@ -28,7 +29,7 @@ export function getShareable(entry: any): Shareable {
tags: meta.tags.map((tag: string) => getTag(tag, type)) || [],
published: getDate(meta.published),
updated: getDate(meta.updated),
url: meta.url,
url: meta.url || '',
slug,
relativePath,
fullPath: `https://harambasic.de${relativePath}`
Expand Down
10 changes: 7 additions & 3 deletions src/lib/data/stack/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '$lib/types/enums';
import { filterByTag, getDate, getTag, sortByDirection } from '$lib/util/entries';
import { getSlug, sortAlphabetical, sortDate } from '$lib/util/helper';
import type { RawEntry } from '$lib/types/entry';

export function filterAndSort(
entries: StackEntry[],
Expand All @@ -22,7 +23,10 @@ export function filterAndSort(
.sort(() => sortByDirection(sortDirection));
}

export function getStackEntry(entry: any): StackEntry {
export function getStackEntry(entry: RawEntry): StackEntry {
if (!entry.meta) {
throw new Error('Missing meta data');
}
const meta = entry.meta;
const type = EntryType.StackEntry;
const slug = getSlug(meta.title);
Expand All @@ -35,9 +39,9 @@ export function getStackEntry(entry: any): StackEntry {
tags: meta.tags.map((tag: string) => getTag(tag, type)) || [],
published: getDate(meta.published),
updated: getDate(meta.updated),
url: meta.url,
url: meta.url || '',
status: meta.status,
openSource: meta.openSource,
openSource: meta.openSource || false,
slug,
relativePath,
fullPath: `https://harambasic.de${relativePath}`
Expand Down
24 changes: 23 additions & 1 deletion src/lib/types/entry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,31 @@ import {
ProjectStatus,
StackEntrySortProperty
} from './enums';
import type { Shareable } from './shareable';
import type { Tag } from './tag';

export interface RawEntry {
html: string;
meta: RawEntryMeta;
toc: TocNode[];
}

export interface RawEntryMeta {
title: string;
description: string;
image: string;
tags: string[];
published: string;
updated: string;
url?: string;
status?: StatusFilter;
openSource?: boolean;
tldr?: string;
discussion?: string;
links?: Link[];
prio?: number;
imageAlt?: string;
}

export interface EntryDate {
raw: Date;
display: string;
Expand Down
39 changes: 21 additions & 18 deletions src/lib/util/converter.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import remarkRehype from 'remark-rehype';
import type { VFile } from 'remark-rehype/lib';
import type { Node } from 'unist';
import { visit } from 'unist-util-visit';
import type { RawEntry, RawEntryMeta } from '$lib/types/entry';

// todo maybe markdown file?
const processor = remark()
Expand All @@ -28,13 +29,16 @@ const processor = remark()
.use(rehypeStringify)
.freeze();

// TODO still needs to be transformed to the corresponding Entry types
export async function getRawEntries(entryType: EntryType): Promise<any[]> {
export async function getRawEntries(entryType: EntryType): Promise<RawEntry[]> {
const files = await _getFiles(entryType);
const entries = await Promise.all(
files.map(async (file) => {
files.map(async (file): Promise<RawEntry> => {
const output = processor.processSync(file);
return { html: output.value, meta: output.data.frontmatter, toc: output.data.toc };
return {
html: String(output.value),
meta: output.data.frontmatter as RawEntryMeta,
toc: output.data.toc as TocNode[]
};
})
);
return entries;
Expand All @@ -55,19 +59,19 @@ export async function _getFiles(entryType: EntryType): Promise<string[]> {

// todo maybe markdown file?
function _rehypeEnhanceImage() {
console.log('_enhanceImage');
return (tree: any) => {
visit(tree, 'element', (node) => {
if (node.tagName === 'img') {
if (!node.properties.src.endsWith('gif') || !node.properties.src.endsWith('svg')) {
// TODO dont get processed by svelte or vite or whoever, need to solve this before putting it life
// node.tagName = 'enhanced:img'
// node.properties.src = `${node.properties.src}?w=1280;640;400`
// node.properties.sizes = '(min-width:1920px) 1280px, (min-width:1080px) 640px, (min-width:768px) 400px'
}
}
});
};
// console.log('_enhanceImage');
// return (tree: Node) => {
// visit(tree, 'element', (node: Element) => {
// if (node.tagName === 'img') {
// if (!node.properties.src.endsWith('gif') || !node.properties.src.endsWith('svg')) {
// // TODO dont get processed by svelte or vite or whoever, need to solve this before putting it life
// // node.tagName = 'enhanced:img'
// // node.properties.src = `${node.properties.src}?w=1280;640;400`
// // node.properties.sizes = '(min-width:1920px) 1280px, (min-width:1080px) 640px, (min-width:768px) 400px'
// }
// }
// });
// };
}

// todo maybe markdown file?
Expand All @@ -78,7 +82,6 @@ interface HeadingNode extends Node {

// todo maybe markdown file?
function _remarkGenerateNestedToc() {
console.log('------------------');
return (tree: Node, file: VFile) => {
const headings: { value: string; depth: number; slug: string }[] = [];
visit(tree, 'heading', (node: HeadingNode) => {
Expand Down
2 changes: 2 additions & 0 deletions src/routes/(main)/posts/[slug]/Entry.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
</div>
<div class="tldr">
<BaseCallout prefix="TL;DR">
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html tldr}
</BaseCallout>
</div>
<section class="post">
<div class="content rich-text e-content">
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html html}
</div>
</section>
Expand Down
1 change: 1 addition & 0 deletions src/routes/(main)/projects/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
{/each}
</ul>
<div class="rich-text">
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html activeProject.html}
</div>
<ul class="links rich-text">
Expand Down
1 change: 0 additions & 1 deletion src/routes/(main)/shareable/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import Entries from '$lib/components/Entries/Entries.svelte';
import EntriesSorter from '$lib/components/Entries/EntriesSorter.svelte';
import EntriesTags from '$lib/components/Entries/EntriesTags.svelte';
import EntriesFilter from '$lib/components/Entries/EntriesFilter.svelte';
import EntriesSidebar from '$lib/components/Entries/EntriesSidebar.svelte';
import { filterAndSort } from '$lib/data/shareable/helper';
import { ShareableSortProperty, SortDirection } from '$lib/types/enums';
Expand Down
5 changes: 4 additions & 1 deletion src/routes/(playground)/cards/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
export let data: PageData;
const {
name,
content,
imageUrl,
fullTitle,
Expand Down Expand Up @@ -69,17 +68,21 @@
<div class="image" style="background-image: url({imageUrl});"></div>
<p class="title">{frontTitle}</p>
<p class="blink">{frontBlink}</p>
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
<p class="generated">{@html frontGenerated}</p>
</div>
<div class="card back">
<p class="greeting">{greeting}</p>
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
<p class="content">{@html content}</p>
<p class="farewell">{farewell} <br /> Luka</p>
<p class="download"><a target="_blank" href={imageUrl}>{backDownload}</a></p>
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
<p class="generated">{@html footerGenerated}</p>
</div>
</article>
<footer>
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
<p>{@html footerBy}</p>
</footer>
</main>
Expand Down
5 changes: 3 additions & 2 deletions src/routes/(playground)/cards/[slug]/getAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function getCurrentPosition(): Promise<GeolocationPosition> {
}

async function fetchLocation(lat: number, lon: number): Promise<Address> {
// TODO change api key and set new one in .env
const API_KEY = 'be669b3d2f4d4c8ea1159c413ac1da78';
try {
const response = await fetch(
Expand All @@ -37,8 +38,8 @@ async function fetchLocation(lat: number, lon: number): Promise<Address> {
line1: address_line1,
line2: address_line2
};
} catch (error: any) {
throw new Error(error.toString());
} catch (error) {
throw new Error(String(error));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/routes/(playground)/cards/[slug]/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function t(key: string, languageCode: string = 'en', value?: any): string {
export function t(key: string, languageCode: string = 'en', value?: never): string {
const languages = import.meta.glob('./i18n.*.ts', { eager: true });
const languageModule = languages[`./i18n.${languageCode}.ts`];
if (!languageModule) {
Expand Down

0 comments on commit 53c4cf8

Please sign in to comment.