This commit is contained in:
Marcel Hellkamp 2024-06-06 14:21:53 +02:00
parent 98fd76dd35
commit 1d13a935ab
6 changed files with 14 additions and 14 deletions

View File

@ -99,7 +99,7 @@ This project was inspired by [Mastowall](https://github.com/rstockm/mastowall),
## License ## License
Copyright (C) 2023 Marcel Hellkamp Copyright (C) 2024 Marcel Hellkamp
Copyright (C) 2023 Gesellschaft für wissenschaftliche Datenverarbeitung mbH Göttingen Copyright (C) 2023 Gesellschaft für wissenschaftliche Datenverarbeitung mbH Göttingen
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

View File

@ -65,11 +65,11 @@ onUpdated(fixLayout)
watch([useWindowSize().width, config, allPosts], fixLayout, { deep: true }) watch([useWindowSize().width, config, allPosts], fixLayout, { deep: true })
// Watch for a theme changes // Watch for a theme changes
const isDarkPrefered = usePreferredDark() const isDarkPreferred = usePreferredDark()
const actualTheme = computed(() => { const actualTheme = computed(() => {
var theme = config.value?.theme var theme = config.value?.theme
if (!theme || theme === "auto") if (!theme || theme === "auto")
theme = isDarkPrefered.value ? "dark" : "light" theme = isDarkPreferred.value ? "dark" : "light"
return theme return theme
}) })
watch(actualTheme, () => { watch(actualTheme, () => {

View File

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { sanatizeConfig, isServer, isLanguage, toQuery } from '@/config'; import { sanitizeConfig, isServer, isLanguage, toQuery } from '@/config';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { arrayUnique } from '@/utils'; import { arrayUnique } from '@/utils';
import { type Config } from '@/types'; import { type Config } from '@/types';
@ -14,7 +14,7 @@ const props = defineProps<{
const config = computed({ const config = computed({
get: () => props.modelValue, get: () => props.modelValue,
set: (value) => emit('update:modelValue', sanatizeConfig(value)), set: (value) => emit('update:modelValue', sanitizeConfig(value)),
}); });
const formServers = computed({ const formServers = computed({
@ -251,7 +251,7 @@ const onSubmit = () => {
<input type="text" class="form-control" id="edit-server" placeholder="all languages" <input type="text" class="form-control" id="edit-server" placeholder="all languages"
v-model.lazy="formLang"> v-model.lazy="formLang">
<div class="form-text">List of <a href="https://en.wikipedia.org/wiki/ISO_639-1" <div class="form-text">List of <a href="https://en.wikipedia.org/wiki/ISO_639-1"
tyrget="_blanlk">two-letter language codes</a> to allow. Leave blank to allow all languages.</div> target="_blank">two-letter language codes</a> to allow. Leave blank to allow all languages.</div>
</div> </div>
</div> </div>

View File

@ -180,7 +180,7 @@ export function fromQuery(query: string): Config {
} }
// Clean, fix and return a valid config // Clean, fix and return a valid config
return sanatizeConfig(config); return sanitizeConfig(config);
} }
export function toQuery(config: Config, userConfig?: string): string { export function toQuery(config: Config, userConfig?: string): string {
@ -223,7 +223,7 @@ export function isLanguage(lang: string) {
return isString(lang) && lang.match(/^[a-z]{2}$/i) return isString(lang) && lang.match(/^[a-z]{2}$/i)
} }
export function sanatizeConfig(config: any): Config { export function sanitizeConfig(config: any): Config {
const boolOr = (value: any, fallback: boolean) => { const boolOr = (value: any, fallback: boolean) => {
if (typeof value == "boolean") return value; if (typeof value == "boolean") return value;
@ -284,7 +284,7 @@ export async function loadConfig() {
try { try {
const rs = await fetch(url, { cache: "reload", }) const rs = await fetch(url, { cache: "reload", })
if (!rs.ok) throw new Error(`HTTP error! Status: ${rs.status}`); if (!rs.ok) throw new Error(`HTTP error! Status: ${rs.status}`);
siteConfig = sanatizeConfig(await rs.json() || {}); siteConfig = sanitizeConfig(await rs.json() || {});
siteConfigSource = url siteConfigSource = url
} catch (e) { } catch (e) {
console.warn(`Failed to load (or parse) [${url}], falling back to defaults.`) console.warn(`Failed to load (or parse) [${url}], falling back to defaults.`)
@ -297,7 +297,7 @@ export async function loadConfig() {
if (!siteConfig && siteConfigUrl) if (!siteConfig && siteConfigUrl)
await loadJson(siteConfigUrl) await loadJson(siteConfigUrl)
if (!siteConfig) if (!siteConfig)
siteConfig = sanatizeConfig(deepClone(fallbackConfig)) siteConfig = sanitizeConfig(deepClone(fallbackConfig))
return fromQuery(window.location.search) return fromQuery(window.location.search)
} }

View File

@ -82,7 +82,7 @@ export async function fetchPosts(cfg: Config, onProgress: (progress: Progress) =
// Collect results // Collect results
const posts: Post[] = [] const posts: Post[] = []
const addOrRepacePost = (post: Post) => { const addOrReplacePost = (post: Post) => {
const i = posts.findIndex(p => p.id === post.id) const i = posts.findIndex(p => p.id === post.id)
if (i >= 0) if (i >= 0)
posts[i] = post posts[i] = post
@ -108,7 +108,7 @@ export async function fetchPosts(cfg: Config, onProgress: (progress: Progress) =
.map(status => fixLocalAcct(domain, status)) .map(status => fixLocalAcct(domain, status))
.filter(status => filterStatus(cfg, status)) .filter(status => filterStatus(cfg, status))
.map(status => statusToWallPost(cfg, status)) .map(status => statusToWallPost(cfg, status))
.forEach(addOrRepacePost) .forEach(addOrReplacePost)
} catch (err: any) { } catch (err: any) {
let error = err instanceof Error ? err : new Error(err?.toString()) let error = err instanceof Error ? err : new Error(err?.toString())
progress.errors.push(error) progress.errors.push(error)

View File

@ -29,11 +29,11 @@ export function deepClone(obj: any) {
/** /**
* Find all text nodes and replace each occuences of a pattern with either * Find all text nodes and replace each occurrences of a pattern with either
* a string or a new DOM node. Can be used to replace emojis with images or * a string or a new DOM node. Can be used to replace emojis with images or
* URLs with links. * URLs with links.
* *
* The root node is modifed in-place and also returned. * The root node is modified in-place and also returned.
*/ */
export function replaceInText(root: Node, pattern: RegExp, replace: (m: RegExpMatchArray) => string | Node) { export function replaceInText(root: Node, pattern: RegExp, replace: (m: RegExpMatchArray) => string | Node) {
const walk = (node: Node) => { const walk = (node: Node) => {