Skip to content

Commit ac5933a

Browse files
Merge pull request #120 from MaddyGuthridge/maddy-sitemap-xml
Improvement for v1.1.7
2 parents 2d88e5a + 94d8849 commit ac5933a

File tree

14 files changed

+303
-52
lines changed

14 files changed

+303
-52
lines changed

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default ts.config(
5656
// strictness in areas where it really doesn't matter (eg error handling)
5757
'@typescript-eslint/no-unsafe-assignment': 'off',
5858
'@typescript-eslint/no-unsafe-argument': 'off',
59+
'@typescript-eslint/no-unsafe-return': 'off',
5960
// Also disable template expression checks, since they're also error handling stuff
6061
// TODO: Enable them at some point when I get around to actually tidying things up
6162
'@typescript-eslint/no-base-to-string': 'off',

package-lock.json

Lines changed: 107 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "minifolio",
3-
"version": "1.1.6",
3+
"version": "1.1.7",
44
"private": true,
55
"license": "GPL-3.0-only",
66
"scripts": {
@@ -39,6 +39,7 @@
3939
"superstruct": "^2.0.2",
4040
"tippy.js": "^6.3.7",
4141
"validator": "^13.12.0",
42+
"xmlbuilder2": "^3.1.1",
4243
"yauzl": "^3.2.0"
4344
},
4445
"devDependencies": {

src/components/markdown/Markdown.svelte

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,20 @@
5555
</div>
5656

5757
<style>
58+
/* Justify text */
5859
.markdown-render :global(p) {
5960
text-align: justify;
6061
}
6162
63+
/* Make images fit in their allocated space */
64+
.markdown-render :global(img) {
65+
width: 100%;
66+
border-radius: 10px;
67+
}
68+
6269
/*
70+
Inline code
71+
6372
It's pretty annoying needing to select all of these manually so many times. I wonder if there's
6473
a better way...
6574
*/
@@ -69,7 +78,6 @@
6978
padding: 2px 5px;
7079
border-radius: 3px;
7180
}
72-
7381
.markdown-render :global(p code),
7482
.markdown-render :global(ol code),
7583
.markdown-render :global(ul code),
@@ -81,11 +89,15 @@
8189
/* Kinda bold but not obnoxiously so */
8290
font-weight: 600;
8391
}
92+
/* Code blocks */
8493
.markdown-render :global(pre) {
8594
padding: 1em;
8695
border-radius: 5px;
8796
}
88-
97+
/*
98+
hljs adds its own padding in the themes which conflicts with our own definitions, causing
99+
annoying visual glitches.
100+
*/
89101
.markdown-render :global(pre code.hljs) {
90102
padding: 0 !important;
91103
}
@@ -112,10 +124,17 @@
112124
display: inline;
113125
}
114126
115-
.markdown-render :global(a) {
116-
text-decoration: none;
117-
}
118-
.markdown-render :global(a):hover {
119-
text-decoration: underline;
127+
/*
128+
Make links not have an underline unless hovered.
129+
130+
This is disabled when high contrast is enabled, which improves visibility.
131+
*/
132+
@media not (prefers-contrast) {
133+
.markdown-render :global(a) {
134+
text-decoration: none;
135+
}
136+
.markdown-render :global(a):hover {
137+
text-decoration: underline;
138+
}
120139
}
121140
</style>

src/endpoints/fetch/response.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { convert } from 'xmlbuilder2';
12
import ApiError from './ApiError';
23

34
/** Process a text response, returning the text as a string */
@@ -17,6 +18,25 @@ export async function text(response: Promise<Response>): Promise<string> {
1718
return text;
1819
}
1920

21+
/** Process an XML response, converting it to a JS object */
22+
export async function xml(response: Promise<Response>): Promise<object> {
23+
// TODO: Fix this coed duplication
24+
const res = await response;
25+
if ([404, 405].includes(res.status)) {
26+
throw new ApiError(404, `Error ${res.status} at ${res.url}`);
27+
}
28+
const text = await res.text();
29+
if ([400, 401, 403].includes(res.status)) {
30+
throw new ApiError(res.status, text);
31+
}
32+
if (![200, 304].includes(res.status)) {
33+
// Unknown error
34+
throw new ApiError(res.status, `Request got status code ${res.status}`);
35+
}
36+
37+
return convert(text, { format: 'object' });
38+
}
39+
2040
/** Process a JSON response, returning the data as a JS object */
2141
export async function json(response: Promise<Response>): Promise<object> {
2242
const res = await response;
@@ -81,6 +101,7 @@ export async function buffer(response: Promise<Response>): Promise<Uint8Array> {
81101
*/
82102
export default (response: Promise<Response>) => ({
83103
json: () => json(response),
104+
xml: () => xml(response),
84105
text: () => text(response),
85106
buffer: () => buffer(response),
86107
response,

src/endpoints/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import type { ItemId } from '$lib/itemId';
33
import admin from './admin';
44
import config from './config';
55
import debug from './debug';
6+
import { apiFetch } from './fetch';
67
import item from './item';
78
import page from './pages';
89

10+
export function sitemap(fetchFn: typeof fetch, token: string | undefined) {
11+
return apiFetch(fetchFn, 'GET', '/sitemap.xml', { token }).xml();
12+
}
13+
914
/** Create an instance of the API client with the given token */
1015
export default function api(fetchFn: typeof fetch = fetch, token?: string) {
1116
return {
@@ -17,6 +22,8 @@ export default function api(fetchFn: typeof fetch = fetch, token?: string) {
1722
config: config(fetchFn, token),
1823
/** Item data endpoints */
1924
item: (itemId: ItemId) => item(fetchFn, token, itemId),
25+
/** Sitemap.xml, converted to JS object */
26+
sitemap: () => sitemap(fetchFn, token),
2027
/** An HTML page */
2128
page: page(fetchFn, token),
2229
/** Create a new API client with the given token */

src/endpoints/pages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ export default function page(fetchFn: typeof fetch, token: string | undefined) {
2424
/** AT Protocol decentralized ID */
2525
atProtoDid: async () => {
2626
return apiFetch(fetchFn, 'GET', '/.well-known/atproto-did', {token}).text();
27-
}
27+
},
2828
};
2929
}

src/lib/itemFilter.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,15 @@ export function createItemFilter(portfolio: ItemData, parentId: ItemId): FilterO
2828
/**
2929
* Returns a list of itemIds within the given groupId that match the given filter
3030
*
31-
* @param globals global data
32-
* @param groupId group ID to find items within
31+
* @param portfolio global data
32+
* @param items list of items to filter on
3333
* @param filter filter options
3434
*/
3535
export function applyFiltersToItemChildren(
3636
portfolio: ItemData,
37-
id: ItemId,
37+
items: ItemId[],
3838
filter: FilterOptions,
3939
): ItemId[] {
40-
// Figure out what items to show to start with
41-
const items: ItemId[] = getDescendant(portfolio, id).info.children.map(child => itemId.child(id, child));
42-
4340
// Reduce items based on the filter
4441
return filter.reduce(
4542
(prevItems, filterSet) => {

src/lib/validate.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ export function validateUrl(url: string): string {
101101
error(400, 'URL protocol must be HTTP or HTTPS');
102102
}
103103

104-
console.log('Protocol:', parsed.protocol);
105-
106104
return url;
107105
}
108106

src/routes/[...item]/+page.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@
5858
} else {
5959
return applyFiltersToItemChildren(
6060
data.portfolio,
61-
data.itemId,
61+
items,
6262
filterItems,
6363
);
6464
}
6565
});
66+
6667
// Janky workaround for allowing PageData to be bindable.
6768
// Based on https://www.reddit.com/r/sveltejs/comments/1gx65ho/comment/lykrc6c/
6869
$effect.pre(() => {

0 commit comments

Comments
 (0)