Compare commits
4 Commits
098da12ac4
...
696082250d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
696082250d
|
||
|
|
c13420c3ab
|
||
|
|
21124dfe00
|
||
|
|
928782c453
|
@@ -15,7 +15,7 @@ COPY . .
|
||||
ENV DATA_DIR=/app/data
|
||||
|
||||
RUN mkdir -p $DATA_DIR && \
|
||||
deno install --allow-import --allow-ffi --allow-scripts=npm:sharp@0.33.5-rc.1 -e main.ts &&\
|
||||
deno install --allow-import --allow-ffi --allow-scripts=npm:sharp -e main.ts &&\
|
||||
sed -i -e 's/"deno"/"no-deno"/' node_modules/@libsql/client/package.json &&\
|
||||
deno task build
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { isYoutubeLink } from "@lib/string.ts";
|
||||
import { IconBrandYoutube } from "@components/icons.tsx";
|
||||
import { GenericResource } from "@lib/types.ts";
|
||||
import { SmallRating } from "@components/Rating.tsx";
|
||||
import { Link } from "@islands/Link.tsx";
|
||||
import { parseRating } from "@lib/helpers.ts";
|
||||
import { GenericResource, getNameOfResource } from "@lib/marka/schema.ts";
|
||||
|
||||
export function Card(
|
||||
{
|
||||
@@ -101,14 +101,16 @@ export function ResourceCard(
|
||||
? `/api/images?image=${img}&width=200&height=200`
|
||||
: "/placeholder.svg";
|
||||
|
||||
const rating = res.content.reviewRating?.ratingValue
|
||||
? parseRating(res.content.reviewRating.ratingValue)
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<Card
|
||||
title={res.content?.name || res.content?.itemReviewed?.name ||
|
||||
res.content?.headline ||
|
||||
res?.name}
|
||||
title={getNameOfResource(res)}
|
||||
backgroundColor={res.image?.average}
|
||||
thumbhash={res.image?.blurhash}
|
||||
rating={parseRating(res.content?.reviewRating?.ratingValue)}
|
||||
thumbhash={res.image?.thumbhash}
|
||||
rating={rating}
|
||||
image={imageUrl}
|
||||
link={`/${sublink}/${res.name.replace(/\.md$/g, "")}`}
|
||||
/>
|
||||
|
||||
@@ -64,8 +64,9 @@ const Image = (
|
||||
style={props.style}
|
||||
srcset={responsiveAttributes.srcset}
|
||||
sizes={responsiveAttributes.sizes}
|
||||
src={`/api/images?image=${asset(props.src)}${props.width ? `&width=${props.width}` : ""
|
||||
}${props.height ? `&height=${props.height}` : ""}`}
|
||||
src={`/api/images?image=${asset(props.src)}${
|
||||
props.width ? `&width=${props.width}` : ""
|
||||
}${props.height ? `&height=${props.height}` : ""}`}
|
||||
width={props.width}
|
||||
height={props.height}
|
||||
class={props.class}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { GenericResource } from "@lib/types.ts";
|
||||
import { Head } from "$fresh/runtime.ts";
|
||||
import { GenericResource, getNameOfResource } from "@lib/marka/schema.ts";
|
||||
import { formatDate } from "@lib/string.ts";
|
||||
|
||||
function generateJsonLd(resource: GenericResource): string {
|
||||
const imageUrl = resource.content?.image
|
||||
@@ -8,34 +9,34 @@ function generateJsonLd(resource: GenericResource): string {
|
||||
|
||||
const baseSchema: Record<string, unknown> = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": resource.content?._type, // Converts type to PascalCase
|
||||
"@type": resource.content?._type,
|
||||
name: resource.name,
|
||||
description: resource.content || resource.meta?.average || "",
|
||||
keywords: resource.tags?.join(", ") || "",
|
||||
description: resource.content || "",
|
||||
keywords: resource.content.keywords?.join(", ") || "",
|
||||
image: imageUrl,
|
||||
};
|
||||
|
||||
if (resource.meta?.author) {
|
||||
if (resource.content?.author) {
|
||||
baseSchema.author = {
|
||||
"@type": "Person",
|
||||
name: resource.meta.author,
|
||||
name: resource.content.author,
|
||||
};
|
||||
}
|
||||
|
||||
if (resource.meta?.date) {
|
||||
if (resource.content?.datePublished) {
|
||||
try {
|
||||
baseSchema.datePublished = new Date(resource.meta.date).toISOString();
|
||||
baseSchema.datePublished = formatDate(
|
||||
new Date(resource.content.datePublished),
|
||||
);
|
||||
} catch (_) {
|
||||
// Ignore invalid date
|
||||
}
|
||||
}
|
||||
|
||||
if (resource.meta?.rating) {
|
||||
baseSchema.aggregateRating = {
|
||||
"@type": "AggregateRating",
|
||||
ratingValue: resource.meta.rating,
|
||||
ratingCount: 1,
|
||||
bestRating: 5, // Assuming a scale of 1 to 10
|
||||
if (resource.content?.reviewRating) {
|
||||
baseSchema.reviewRating = {
|
||||
"@type": "Rating",
|
||||
...resource.content.reviewRating,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -51,7 +52,7 @@ export function MetaTags({ resource }: { resource: GenericResource }) {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<meta property="og:title" content={resource.content?.name} />
|
||||
<meta property="og:title" content={getNameOfResource(resource)} />
|
||||
<meta property="og:type" content={resource.content?._type} />
|
||||
<meta
|
||||
property="og:image"
|
||||
|
||||
@@ -20,8 +20,9 @@ function Wrapper(
|
||||
) {
|
||||
return (
|
||||
<div
|
||||
class={`flex justify-between flex-col relative w-full ${image ? "min-h-[400px]" : "min-h-[200px]"
|
||||
} rounded-3xl overflow-hidden`}
|
||||
class={`flex justify-between flex-col relative w-full ${
|
||||
image ? "min-h-[400px]" : "min-h-[200px]"
|
||||
} rounded-3xl overflow-hidden`}
|
||||
>
|
||||
<HeroContext.Provider value={{ image }}>
|
||||
{image &&
|
||||
@@ -51,8 +52,9 @@ function Title(
|
||||
return (
|
||||
<OuterTag
|
||||
href={link}
|
||||
class={`${ctx.image ? "noisy-gradient" : ""
|
||||
} after:opacity-90 flex gap-4 items-center ${ctx.image ? "pt-12" : ""}`}
|
||||
class={`${
|
||||
ctx.image ? "noisy-gradient" : ""
|
||||
} after:opacity-90 flex gap-4 items-center ${ctx.image ? "pt-12" : ""}`}
|
||||
>
|
||||
<h2
|
||||
class="flex gap-2 items-center text-4xl font-bold z-10"
|
||||
@@ -81,8 +83,9 @@ function EditLink({ href }: { href: string }) {
|
||||
const ctx = useContext(HeroContext);
|
||||
return (
|
||||
<a
|
||||
class={`px-4 py-2 ${ctx.image ? "bg-gray-300 text-gray-800" : "text-gray-200"
|
||||
} rounded-lg flex gap-1 items-center`}
|
||||
class={`px-4 py-2 ${
|
||||
ctx.image ? "bg-gray-300 text-gray-800" : "text-gray-200"
|
||||
} rounded-lg flex gap-1 items-center`}
|
||||
href={href}
|
||||
>
|
||||
<IconEdit class="w-5 h-5" />
|
||||
@@ -101,7 +104,7 @@ function Header({ children }: { children: ComponentChildren }) {
|
||||
function Subline(
|
||||
{ entries, children }: {
|
||||
children?: ComponentChildren;
|
||||
entries: (string | { href: string; title: string })[];
|
||||
entries: (string | undefined | { href: string; title: string })[];
|
||||
},
|
||||
) {
|
||||
const ctx = useContext(HeroContext);
|
||||
@@ -114,10 +117,11 @@ function Subline(
|
||||
{entries.filter((s) =>
|
||||
s && (typeof s === "string" ? s?.length > 1 : true)
|
||||
).map((s) => {
|
||||
if (!s) return;
|
||||
if (typeof s === "string") {
|
||||
return <span>{s}</span>;
|
||||
return <span key={s}>{s}</span>;
|
||||
} else {
|
||||
return <a href={s.href}>{s.title}</a>;
|
||||
return <a key={s.href} href={s.href}>{s.title}</a>;
|
||||
}
|
||||
})}
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ComponentChildren } from "preact";
|
||||
import Search from "@islands/Search.tsx";
|
||||
import { GenericResource } from "@lib/types.ts";
|
||||
import { GenericResource } from "@lib/marka/schema.ts";
|
||||
|
||||
export type Props = {
|
||||
children: ComponentChildren;
|
||||
@@ -21,7 +21,7 @@ export const MainLayout = (
|
||||
if (hasSearch) {
|
||||
return (
|
||||
<Search
|
||||
q={_url.searchParams.get("q")}
|
||||
q={_url.searchParams.get("q") || ""}
|
||||
{...context}
|
||||
results={searchResults}
|
||||
/>
|
||||
|
||||
10
compose.yml
10
compose.yml
@@ -4,10 +4,10 @@ services:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
volumes:
|
||||
- .:/app # Mount the local directory to /app in the container
|
||||
working_dir: /app # Set the working directory inside the container to /app
|
||||
command: run --env-file -A --watch=static/,routes/ dev.ts # Custom start command
|
||||
- .:/app # Mount the local directory to /app in the container
|
||||
working_dir: /app # Set the working directory inside the container to /app
|
||||
command: run --env-file -A --watch=static/,routes/ dev.ts # Custom start command
|
||||
ports:
|
||||
- "8000:8000" # Expose the container port
|
||||
- "8000:8000" # Expose the container port
|
||||
environment:
|
||||
- DATA_DIR=/app/data # Set the environment variable inside the container
|
||||
- DATA_DIR=/app/data # Set the environment variable inside the container
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
"@lib": "./lib",
|
||||
"@lib/": "./lib/",
|
||||
"@libsql/client": "npm:@libsql/client@^0.14.0",
|
||||
"@openai/openai": "jsr:@openai/openai@^6.7.0",
|
||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.2.2",
|
||||
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.1",
|
||||
"@std/http": "jsr:@std/http@^1.0.12",
|
||||
|
||||
@@ -2,7 +2,6 @@ import { Signal } from "@preact/signals";
|
||||
import type { Ingredient, IngredientGroup } from "@lib/recipeSchema.ts";
|
||||
import { FunctionalComponent } from "preact";
|
||||
import { unitsOfMeasure } from "@lib/parseIngredient.ts";
|
||||
import { renderMarkdown } from "@lib/markdown.ts";
|
||||
|
||||
function formatAmount(num: number) {
|
||||
if (num === 0) return "";
|
||||
@@ -10,15 +9,12 @@ function formatAmount(num: number) {
|
||||
}
|
||||
|
||||
function formatUnit(unit: string, amount: number) {
|
||||
const unitKey = unit.toLowerCase() as keyof typeof unitsOfMeasure;
|
||||
if (!unit) return "";
|
||||
const unitKey = unit.toLowerCase() as (keyof typeof unitsOfMeasure);
|
||||
if (unitKey in unitsOfMeasure) {
|
||||
if (amount > 1 && unitsOfMeasure[unitKey].plural !== undefined) {
|
||||
return unitsOfMeasure[unitKey].plural;
|
||||
}
|
||||
if (unitKey !== "cup") {
|
||||
return unitsOfMeasure[unitKey].short;
|
||||
}
|
||||
|
||||
return unitKey.toString();
|
||||
} else {
|
||||
return unit;
|
||||
@@ -63,15 +59,28 @@ export const IngredientsList: FunctionalComponent<
|
||||
> = (
|
||||
{ ingredients, amount, portion },
|
||||
) => {
|
||||
return (
|
||||
<table class="w-full border-collapse table-auto">
|
||||
<tbody>
|
||||
{ingredients.map((item) => {
|
||||
return (
|
||||
<table class="w-full border-collapse table-auto">
|
||||
<tbody>
|
||||
{ingredients.map((item) => {
|
||||
if ("items" in item) {
|
||||
return item.items.map((ing, i) => {
|
||||
return (
|
||||
<Ingredient
|
||||
key={i}
|
||||
ingredient={ing}
|
||||
amount={amount}
|
||||
portion={portion}
|
||||
/>
|
||||
);
|
||||
});
|
||||
} else {
|
||||
return (
|
||||
<Ingredient ingredient={item} amount={amount} portion={portion} />
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
};
|
||||
}
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -103,8 +103,9 @@ export const KMenu = (
|
||||
}
|
||||
|
||||
useEventListener("keydown", (ev: KeyboardEvent) => {
|
||||
const target = ev.target as HTMLElement;
|
||||
if (ev.key === "k") {
|
||||
if (ev?.target?.nodeName == "INPUT") {
|
||||
if (target.nodeName == "INPUT") {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ type IconKey = keyof typeof icons;
|
||||
export type MenuState = {
|
||||
activeMenu: Signal<string>;
|
||||
activeState: Signal<"input" | "error" | "normal" | "loading">;
|
||||
loadingText:Signal<string>;
|
||||
loadingText: Signal<string>;
|
||||
commandInput: Signal<string>;
|
||||
visible: Signal<boolean>;
|
||||
menus: Record<string, Menu>;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useEffect } from "preact/hooks";
|
||||
|
||||
declare global {
|
||||
// deno-lint-ignore no-var
|
||||
var loadingTimeout: ReturnType<typeof setTimeout> | undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useCallback, useState } from "preact/hooks";
|
||||
import { IconWand } from "@components/icons.tsx";
|
||||
import { RecommendationResource } from "@lib/recommendation.ts";
|
||||
|
||||
type RecommendationState = "disabled" | "loading";
|
||||
|
||||
@@ -11,7 +12,7 @@ export function Recommendations(
|
||||
},
|
||||
) {
|
||||
const [state, setState] = useState<RecommendationState>("disabled");
|
||||
const [results, setResults] = useState();
|
||||
const [results, setResults] = useState<RecommendationResource[]>();
|
||||
|
||||
const startFetch = useCallback(
|
||||
async () => {
|
||||
@@ -44,9 +45,9 @@ export function Recommendations(
|
||||
<div class="flex gap-5 items-center mb-4">
|
||||
<img
|
||||
class="w-12 h-12 rounded-full object-cover"
|
||||
src={`https://image.tmdb.org/t/p/original${res.poster_path}`}
|
||||
src={`https://image.tmdb.org/t/p/original${res.id}`}
|
||||
/>
|
||||
<p>{res.title}</p>
|
||||
<p>{res.id}</p>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
@@ -66,6 +67,7 @@ export function Recommendations(
|
||||
{!results && state === "disabled" &&
|
||||
(
|
||||
<button
|
||||
type="submit"
|
||||
onClick={startFetch}
|
||||
class="ml-8 mt-2 font-thin flex items-center gap-2 text-white my-2"
|
||||
>
|
||||
|
||||
@@ -10,7 +10,7 @@ import { Rating } from "@components/Rating.tsx";
|
||||
import { useSignal } from "@preact/signals";
|
||||
import Image from "@components/Image.tsx";
|
||||
import { Emoji } from "@components/Emoji.tsx";
|
||||
import { GenericResource } from "@lib/marka/schema.ts";
|
||||
import { GenericResource, getNameOfResource } from "@lib/marka/schema.ts";
|
||||
|
||||
export async function fetchQueryResource(url: URL, type = "") {
|
||||
const query = url.searchParams.get("q");
|
||||
@@ -33,21 +33,23 @@ export async function fetchQueryResource(url: URL, type = "") {
|
||||
}
|
||||
}
|
||||
|
||||
export const RedirectSearchHandler = () => {
|
||||
if (getCookie("session_cookie")) {
|
||||
useEventListener("keydown", (e: KeyboardEvent) => {
|
||||
if (e?.target?.nodeName == "INPUT") return;
|
||||
export function RedirectSearchHandler() {
|
||||
useEventListener("keydown", (e: KeyboardEvent) => {
|
||||
if (getCookie("session_cookie")) {
|
||||
const target = e.target as HTMLInputElement;
|
||||
if (target.nodeName == "INPUT") return;
|
||||
if (
|
||||
e.key === "?" &&
|
||||
globalThis.location.search === ""
|
||||
) {
|
||||
globalThis.location.href += "?q=";
|
||||
}
|
||||
}, IS_BROWSER ? document?.body : undefined);
|
||||
}
|
||||
}
|
||||
}, IS_BROWSER ? document?.body : undefined);
|
||||
|
||||
return;
|
||||
};
|
||||
// deno-lint-ignore jsx-no-useless-fragment
|
||||
return <></>;
|
||||
}
|
||||
|
||||
const SearchResultImage = ({ src }: { src: string }) => {
|
||||
return (
|
||||
@@ -67,7 +69,8 @@ export const SearchResultItem = (
|
||||
showEmoji?: boolean;
|
||||
},
|
||||
) => {
|
||||
const resourceType = resources[item?.content._type];
|
||||
const resourceType =
|
||||
resources[item.content._type.toLowerCase() as keyof typeof resources];
|
||||
const href = item?.path.replace("/resources", "").replace(/\.md$/, "");
|
||||
return (
|
||||
<a
|
||||
@@ -78,8 +81,7 @@ export const SearchResultItem = (
|
||||
? <Emoji class="w-7 h-7" name={resourceType.emoji} />
|
||||
: ""}
|
||||
{item.image && <SearchResultImage src={item.image?.url} />}
|
||||
{item.content?.headline || item.content?.name ||
|
||||
item.content?.itemReviewed.name || item?.name}
|
||||
{getNameOfResource(item)}
|
||||
</a>
|
||||
);
|
||||
};
|
||||
@@ -191,16 +193,16 @@ const Search = (
|
||||
{data.value?.length && !isLoading.value
|
||||
? <SearchResultList showEmoji={!type} result={data.value} />
|
||||
: isLoading.value
|
||||
? <div />
|
||||
: (
|
||||
<div
|
||||
class="flex items-center gap-2 p-2 my-4 mx-3"
|
||||
style={{ color: "#818181" }}
|
||||
>
|
||||
<Emoji class="w-8 h-8" name="Ghost.png" />
|
||||
No Results
|
||||
</div>
|
||||
)}
|
||||
? <div />
|
||||
: (
|
||||
<div
|
||||
class="flex items-center gap-2 p-2 my-4 mx-3"
|
||||
style={{ color: "#818181" }}
|
||||
>
|
||||
<Emoji class="w-8 h-8" name="Ghost.png" />
|
||||
No Results
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -102,17 +102,14 @@ export function debounce<T extends (...args: Parameters<T>) => void>(
|
||||
}
|
||||
|
||||
export function parseRating(rating: string | number) {
|
||||
if (typeof rating === "string") {
|
||||
try {
|
||||
const res = parseInt(rating);
|
||||
if (!Number.isNaN(res)) return res;
|
||||
} catch (_e) {
|
||||
// This is okay
|
||||
}
|
||||
|
||||
return rating.length / 2;
|
||||
if (typeof rating == "number") return rating;
|
||||
try {
|
||||
const res = parseInt(rating);
|
||||
if (!Number.isNaN(res)) return res;
|
||||
} catch (_e) {
|
||||
// This is okay
|
||||
}
|
||||
return rating;
|
||||
return rating.length / 2;
|
||||
}
|
||||
|
||||
export async function convertOggToMp3(
|
||||
|
||||
@@ -1,286 +1,93 @@
|
||||
import { useEffect, useMemo, useRef } from "preact/hooks";
|
||||
|
||||
export interface CallOptions {
|
||||
/**
|
||||
* Controls if the function should be invoked on the leading edge of the timeout.
|
||||
*/
|
||||
leading?: boolean;
|
||||
/**
|
||||
* Controls if the function should be invoked on the trailing edge of the timeout.
|
||||
*/
|
||||
trailing?: boolean;
|
||||
}
|
||||
type Debounced<T extends (...args: unknown[]) => unknown> =
|
||||
& ((
|
||||
...args: Parameters<T>
|
||||
) => void)
|
||||
& {
|
||||
cancel: () => void;
|
||||
flush: () => void;
|
||||
pending: () => boolean;
|
||||
};
|
||||
|
||||
export interface Options extends CallOptions {
|
||||
/**
|
||||
* The maximum time the given function is allowed to be delayed before it's invoked.
|
||||
*/
|
||||
maxWait?: number;
|
||||
}
|
||||
|
||||
export interface ControlFunctions {
|
||||
/**
|
||||
* Cancel pending function invocations
|
||||
*/
|
||||
cancel: () => void;
|
||||
/**
|
||||
* Immediately invoke pending function invocations
|
||||
*/
|
||||
flush: () => void;
|
||||
/**
|
||||
* Returns `true` if there are any pending function invocations
|
||||
*/
|
||||
isPending: () => boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subsequent calls to the debounced function `debounced.callback` return the result of the last func invocation.
|
||||
* Note, that if there are no previous invocations it's mean you will get undefined. You should check it in your code properly.
|
||||
*/
|
||||
export interface DebouncedState<T extends (...args: any) => ReturnType<T>>
|
||||
extends ControlFunctions {
|
||||
(...args: Parameters<T>): ReturnType<T> | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a debounced function that delays invoking `func` until after `wait`
|
||||
* milliseconds have elapsed since the last time the debounced function was
|
||||
* invoked, or until the next browser frame is drawn.
|
||||
*
|
||||
* The debounced function comes with a `cancel` method to cancel delayed `func`
|
||||
* invocations and a `flush` method to immediately invoke them.
|
||||
*
|
||||
* Provide `options` to indicate whether `func` should be invoked on the leading
|
||||
* and/or trailing edge of the `wait` timeout. The `func` is invoked with the
|
||||
* last arguments provided to the debounced function.
|
||||
*
|
||||
* Subsequent calls to the debounced function return the result of the last
|
||||
* `func` invocation.
|
||||
*
|
||||
* **Note:** If `leading` and `trailing` options are `true`, `func` is
|
||||
* invoked on the trailing edge of the timeout only if the debounced function
|
||||
* is invoked more than once during the `wait` timeout.
|
||||
*
|
||||
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
||||
* until the next tick, similar to `setTimeout` with a timeout of `0`.
|
||||
*
|
||||
* If `wait` is omitted in an environment with `requestAnimationFrame`, `func`
|
||||
* invocation will be deferred until the next frame is drawn (typically about
|
||||
* 16ms).
|
||||
*
|
||||
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
|
||||
* for details over the differences between `debounce` and `throttle`.
|
||||
*
|
||||
* @category Function
|
||||
* @param {Function} func The function to debounce.
|
||||
* @param {number} [wait=0]
|
||||
* The number of milliseconds to delay; if omitted, `requestAnimationFrame` is
|
||||
* used (if available, otherwise it will be setTimeout(...,0)).
|
||||
* @param {Object} [options={}] The options object.
|
||||
* Controls if `func` should be invoked on the leading edge of the timeout.
|
||||
* @param {boolean} [options.leading=false]
|
||||
* The maximum time `func` is allowed to be delayed before it's invoked.
|
||||
* @param {number} [options.maxWait]
|
||||
* Controls if `func` should be invoked the trailing edge of the timeout.
|
||||
* @param {boolean} [options.trailing=true]
|
||||
* @returns {Function} Returns the new debounced function.
|
||||
* @example
|
||||
*
|
||||
* // Avoid costly calculations while the window size is in flux.
|
||||
* const resizeHandler = useDebouncedCallback(calculateLayout, 150);
|
||||
* window.addEventListener('resize', resizeHandler)
|
||||
*
|
||||
* // Invoke `sendMail` when clicked, debouncing subsequent calls.
|
||||
* const clickHandler = useDebouncedCallback(sendMail, 300, {
|
||||
* leading: true,
|
||||
* trailing: false,
|
||||
* })
|
||||
* <button onClick={clickHandler}>click me</button>
|
||||
*
|
||||
* // Ensure `batchLog` is invoked once after 1 second of debounced calls.
|
||||
* const debounced = useDebouncedCallback(batchLog, 250, { 'maxWait': 1000 })
|
||||
* const source = new EventSource('/stream')
|
||||
* source.addEventListener('message', debounced)
|
||||
*
|
||||
* // Cancel the trailing debounced invocation.
|
||||
* window.addEventListener('popstate', debounced.cancel)
|
||||
*
|
||||
* // Check for pending invocations.
|
||||
* const status = debounced.pending() ? "Pending..." : "Ready"
|
||||
*/
|
||||
export default function useDebouncedCallback<
|
||||
T extends (...args: any) => ReturnType<T>,
|
||||
T extends (...args: unknown[]) => unknown,
|
||||
>(
|
||||
func: T,
|
||||
wait?: number,
|
||||
options?: Options,
|
||||
): DebouncedState<T> {
|
||||
const lastCallTime = useRef(null);
|
||||
const lastInvokeTime = useRef(0);
|
||||
const timerId = useRef(null);
|
||||
const lastArgs = useRef<unknown[]>([]);
|
||||
const lastThis = useRef<unknown>();
|
||||
const result = useRef<ReturnType<T>>();
|
||||
const funcRef = useRef(func);
|
||||
const mounted = useRef(true);
|
||||
callback: T,
|
||||
delay: number,
|
||||
options?: {
|
||||
/** Call on the leading edge. Default: false */
|
||||
leading?: boolean;
|
||||
/** Call on the trailing edge. Default: true */
|
||||
trailing?: boolean;
|
||||
},
|
||||
): Debounced<T> {
|
||||
const callbackRef = useRef(callback);
|
||||
const timerRef = useRef<number | null>(null);
|
||||
const argsRef = useRef<Parameters<T> | null>(null);
|
||||
|
||||
// Always use the latest callback without re-creating the debounced fn
|
||||
useEffect(() => {
|
||||
funcRef.current = func;
|
||||
}, [func]);
|
||||
callbackRef.current = callback;
|
||||
}, [callback]);
|
||||
|
||||
// Bypass `requestAnimationFrame` by explicitly setting `wait=0`.
|
||||
const useRAF = !wait && wait !== 0 && typeof window !== "undefined";
|
||||
const leading = !!options?.leading;
|
||||
const trailing = options?.trailing !== false; // default true
|
||||
|
||||
if (typeof func !== "function") {
|
||||
throw new TypeError("Expected a function");
|
||||
}
|
||||
|
||||
wait = +wait || 0;
|
||||
options = options || {};
|
||||
|
||||
const leading = !!options.leading;
|
||||
const trailing = "trailing" in options ? !!options.trailing : true; // `true` by default
|
||||
const maxing = "maxWait" in options;
|
||||
const maxWait = maxing ? Math.max(+options.maxWait || 0, wait) : null;
|
||||
|
||||
useEffect(() => {
|
||||
mounted.current = true;
|
||||
return () => {
|
||||
mounted.current = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
// You may have a question, why we have so many code under the useMemo definition.
|
||||
//
|
||||
// This was made as we want to escape from useCallback hell and
|
||||
// not to initialize a number of functions each time useDebouncedCallback is called.
|
||||
//
|
||||
// It means that we have less garbage for our GC calls which improves performance.
|
||||
// Also, it makes this library smaller.
|
||||
//
|
||||
// And the last reason, that the code without lots of useCallback with deps is easier to read.
|
||||
// You have only one place for that.
|
||||
const debounced = useMemo(() => {
|
||||
const invokeFunc = (time: number) => {
|
||||
const args = lastArgs.current;
|
||||
const thisArg = lastThis.current;
|
||||
|
||||
lastArgs.current = lastThis.current = null;
|
||||
lastInvokeTime.current = time;
|
||||
return (result.current = funcRef.current.apply(thisArg, args));
|
||||
};
|
||||
|
||||
const startTimer = (pendingFunc: () => void, wait: number) => {
|
||||
if (useRAF) cancelAnimationFrame(timerId.current);
|
||||
timerId.current = useRAF
|
||||
? requestAnimationFrame(pendingFunc)
|
||||
: setTimeout(pendingFunc, wait);
|
||||
};
|
||||
|
||||
const shouldInvoke = (time: number) => {
|
||||
if (!mounted.current) return false;
|
||||
|
||||
const timeSinceLastCall = time - lastCallTime.current;
|
||||
const timeSinceLastInvoke = time - lastInvokeTime.current;
|
||||
|
||||
// Either this is the first call, activity has stopped and we're at the
|
||||
// trailing edge, the system time has gone backwards and we're treating
|
||||
// it as the trailing edge, or we've hit the `maxWait` limit.
|
||||
return (
|
||||
!lastCallTime.current ||
|
||||
timeSinceLastCall >= wait ||
|
||||
timeSinceLastCall < 0 ||
|
||||
(maxing && timeSinceLastInvoke >= maxWait)
|
||||
);
|
||||
};
|
||||
|
||||
const trailingEdge = (time: number) => {
|
||||
timerId.current = null;
|
||||
|
||||
// Only invoke if we have `lastArgs` which means `func` has been
|
||||
// debounced at least once.
|
||||
if (trailing && lastArgs.current) {
|
||||
return invokeFunc(time);
|
||||
const debounced = useMemo<Debounced<T>>(() => {
|
||||
const clear = () => {
|
||||
if (timerRef.current != null) {
|
||||
clearTimeout(timerRef.current);
|
||||
timerRef.current = null;
|
||||
}
|
||||
lastArgs.current = lastThis.current = null;
|
||||
return result.current;
|
||||
};
|
||||
|
||||
const timerExpired = () => {
|
||||
const time = Date.now();
|
||||
if (shouldInvoke(time)) {
|
||||
return trailingEdge(time);
|
||||
const invoke = () => {
|
||||
const a = argsRef.current;
|
||||
argsRef.current = null;
|
||||
if (a) {
|
||||
callbackRef.current(...a);
|
||||
}
|
||||
// https://github.com/xnimorz/use-debounce/issues/97
|
||||
if (!mounted.current) {
|
||||
return;
|
||||
};
|
||||
|
||||
const fn = ((...args: Parameters<T>) => {
|
||||
const shouldCallLeading = leading && timerRef.current == null;
|
||||
|
||||
argsRef.current = args;
|
||||
|
||||
if (timerRef.current != null) clearTimeout(timerRef.current);
|
||||
|
||||
timerRef.current = globalThis.setTimeout(() => {
|
||||
timerRef.current = null;
|
||||
if (trailing) invoke();
|
||||
}, delay);
|
||||
|
||||
if (shouldCallLeading) {
|
||||
// Leading edge call happens immediately
|
||||
invoke();
|
||||
}
|
||||
// Remaining wait calculation
|
||||
const timeSinceLastCall = time - lastCallTime.current;
|
||||
const timeSinceLastInvoke = time - lastInvokeTime.current;
|
||||
const timeWaiting = wait - timeSinceLastCall;
|
||||
const remainingWait = maxing
|
||||
? Math.min(timeWaiting, maxWait - timeSinceLastInvoke)
|
||||
: timeWaiting;
|
||||
}) as Debounced<T>;
|
||||
|
||||
// Restart the timer
|
||||
startTimer(timerExpired, remainingWait);
|
||||
fn.cancel = () => {
|
||||
argsRef.current = null;
|
||||
clear();
|
||||
};
|
||||
|
||||
const func: DebouncedState<T> = (...args: Parameters<T>): ReturnType<T> => {
|
||||
const time = Date.now();
|
||||
const isInvoking = shouldInvoke(time);
|
||||
|
||||
lastArgs.current = args;
|
||||
lastThis.current = this;
|
||||
lastCallTime.current = time;
|
||||
|
||||
if (isInvoking) {
|
||||
if (!timerId.current && mounted.current) {
|
||||
// Reset any `maxWait` timer.
|
||||
lastInvokeTime.current = lastCallTime.current;
|
||||
// Start the timer for the trailing edge.
|
||||
startTimer(timerExpired, wait);
|
||||
// Invoke the leading edge.
|
||||
return leading ? invokeFunc(lastCallTime.current) : result.current;
|
||||
}
|
||||
if (maxing) {
|
||||
// Handle invocations in a tight loop.
|
||||
startTimer(timerExpired, wait);
|
||||
return invokeFunc(lastCallTime.current);
|
||||
}
|
||||
fn.flush = () => {
|
||||
if (timerRef.current != null) {
|
||||
clear();
|
||||
invoke();
|
||||
}
|
||||
if (!timerId.current) {
|
||||
startTimer(timerExpired, wait);
|
||||
}
|
||||
return result.current;
|
||||
};
|
||||
|
||||
func.cancel = () => {
|
||||
if (timerId.current) {
|
||||
useRAF
|
||||
? cancelAnimationFrame(timerId.current)
|
||||
: clearTimeout(timerId.current);
|
||||
}
|
||||
lastInvokeTime.current = 0;
|
||||
lastArgs.current =
|
||||
lastCallTime.current =
|
||||
lastThis.current =
|
||||
timerId.current =
|
||||
null;
|
||||
};
|
||||
fn.pending = () => timerRef.current != null;
|
||||
|
||||
func.isPending = () => {
|
||||
return !!timerId.current;
|
||||
};
|
||||
return fn;
|
||||
// Recreate only if timing/edge behavior changes
|
||||
}, [delay, leading, trailing]);
|
||||
|
||||
func.flush = () => {
|
||||
return !timerId.current ? result.current : trailingEdge(Date.now());
|
||||
};
|
||||
|
||||
return func;
|
||||
}, [leading, maxing, wait, maxWait, trailing, useRAF]);
|
||||
// Cancel on unmount
|
||||
useEffect(() => () => debounced.cancel(), [debounced]);
|
||||
|
||||
return debounced;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ export function useEventListener<T extends Event>(
|
||||
element: typeof globalThis | HTMLElement = globalThis,
|
||||
) {
|
||||
// Create a ref that stores handler
|
||||
const savedHandler = useRef<(event: Event) => void>();
|
||||
const savedHandler = useRef<(event: T) => void>();
|
||||
|
||||
// Update ref.current value if handler changes.
|
||||
// This allows our effect below to always get latest handler ...
|
||||
@@ -27,11 +27,11 @@ export function useEventListener<T extends Event>(
|
||||
const eventListener = (event: T) => savedHandler?.current?.(event);
|
||||
|
||||
// Add event listener
|
||||
element.addEventListener(eventName, eventListener);
|
||||
element.addEventListener(eventName, (ev) => eventListener(ev as T));
|
||||
|
||||
// Remove event listener on cleanup
|
||||
return () => {
|
||||
element.removeEventListener(eventName, eventListener);
|
||||
element.removeEventListener(eventName, (ev) => eventListener(ev as T));
|
||||
};
|
||||
},
|
||||
[eventName, element], // Re-run if eventName or element changes
|
||||
|
||||
@@ -6,7 +6,7 @@ type ThrottleOptions = {
|
||||
};
|
||||
|
||||
const useThrottledCallback = (
|
||||
callback: (...args: any[]) => void,
|
||||
callback: (...args: unknown[]) => void,
|
||||
delay: number,
|
||||
options: ThrottleOptions = {},
|
||||
) => {
|
||||
@@ -24,7 +24,7 @@ const useThrottledCallback = (
|
||||
};
|
||||
}, [timer]);
|
||||
|
||||
const throttledCallback = (...args: any[]) => {
|
||||
const throttledCallback = (...args: unknown[]) => {
|
||||
const now = Date.now();
|
||||
|
||||
if (leading && !isLeading) {
|
||||
@@ -52,4 +52,3 @@ const useThrottledCallback = (
|
||||
};
|
||||
|
||||
export default useThrottledCallback;
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import { useEffect, useRef } from "preact/hooks";
|
||||
|
||||
export function useTraceUpdate(props) {
|
||||
export function useTraceUpdate(props: Record<string, unknown>) {
|
||||
const prev = useRef(props);
|
||||
useEffect(() => {
|
||||
const changedProps = Object.entries(props).reduce((ps, [k, v]) => {
|
||||
if (prev.current[k] !== v) {
|
||||
ps[k] = [prev.current[k], v];
|
||||
}
|
||||
return ps;
|
||||
}, {});
|
||||
const changedProps = Object.entries(props).reduce(
|
||||
(ps: Record<string, unknown>, [k, v]) => {
|
||||
if (prev.current[k] !== v) {
|
||||
ps[k] = [prev.current[k], v];
|
||||
}
|
||||
return ps;
|
||||
},
|
||||
{},
|
||||
);
|
||||
if (Object.keys(changedProps).length > 0) {
|
||||
console.log("Changed props:", changedProps);
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ async function getLocalImage(
|
||||
*/
|
||||
async function storeLocalImage(
|
||||
url: string,
|
||||
content: ArrayBuffer,
|
||||
content: Uint8Array<ArrayBuffer> | ArrayBuffer,
|
||||
{ width, height }: { width?: number; height?: number } = {},
|
||||
) {
|
||||
const isValid = await verifyImage(new Uint8Array(content));
|
||||
@@ -249,7 +249,7 @@ async function verifyImage(imageBuffer: Uint8Array): Promise<boolean> {
|
||||
export async function getImageContent(
|
||||
url: string,
|
||||
{ width, height }: { width?: number; height?: number } = {},
|
||||
): Promise<{ content: ArrayBuffer; mimeType: string }> {
|
||||
): Promise<{ content: Uint8Array<ArrayBuffer>; mimeType: string }> {
|
||||
log.debug("Getting image content", { url, width, height });
|
||||
|
||||
// Check if we have the image metadata in database
|
||||
@@ -267,8 +267,8 @@ export async function getImageContent(
|
||||
// Fetch and cache original if needed
|
||||
if (!originalImage) {
|
||||
const fetchedImage = await getRemoteImage(url);
|
||||
await storeLocalImage(url, fetchedImage.buffer);
|
||||
originalImage = new Uint8Array(fetchedImage.buffer);
|
||||
await storeLocalImage(url, originalImage);
|
||||
}
|
||||
|
||||
// Resize image
|
||||
|
||||
@@ -12,7 +12,7 @@ async function addImageToResource<T extends GenericResource>(
|
||||
if (imageUrl) {
|
||||
try {
|
||||
const absoluteImageUrl = (imageUrl.startsWith("https://") ||
|
||||
imageUrl.startsWith("http://"))
|
||||
imageUrl.startsWith("http://"))
|
||||
? imageUrl
|
||||
: `${url}/${imageUrl}`;
|
||||
const image = await getImage(absoluteImageUrl);
|
||||
|
||||
@@ -68,6 +68,7 @@ export const ReviewContentSchema = makeContentSchema("Review", {
|
||||
export const RecipeContentSchema = makeContentSchema("Recipe", {
|
||||
description: z.string().optional(),
|
||||
name: z.string().optional(),
|
||||
reviewRating: ReviewRatingSchema.optional(),
|
||||
recipeIngredient: z.array(z.string()).optional(),
|
||||
recipeInstructions: z.array(z.string()).optional(),
|
||||
totalTime: z.string().optional(),
|
||||
@@ -124,3 +125,16 @@ export type RecipeResource = z.infer<typeof RecipeSchema> & {
|
||||
export type GenericResource = z.infer<typeof GenericResourceSchema> & {
|
||||
image?: typeof imageTable.$inferSelect;
|
||||
};
|
||||
|
||||
export function getNameOfResource(res: GenericResource): string {
|
||||
if (res.content?._type === "Article" && res.content.headline) {
|
||||
return res.content.headline;
|
||||
}
|
||||
if (res.content?._type === "Review" && res.content.itemReviewed?.name) {
|
||||
return res.content.itemReviewed.name;
|
||||
}
|
||||
if (res.content?._type === "Recipe" && res.content.name) {
|
||||
return res.content.name;
|
||||
}
|
||||
return "Unnamed Resource";
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import OpenAI from "https://deno.land/x/openai@v4.69.0/mod.ts";
|
||||
import { zodResponseFormat } from "https://deno.land/x/openai@v4.69.0/helpers/zod.ts";
|
||||
import OpenAI, { toFile } from "@openai/openai";
|
||||
import { zodResponseFormat } from "@openai/openai/helpers/zod";
|
||||
import { OPENAI_API_KEY } from "@lib/env.ts";
|
||||
import { hashString } from "@lib/helpers.ts";
|
||||
import { createCache } from "@lib/cache.ts";
|
||||
@@ -35,7 +35,8 @@ export async function summarize(content: string) {
|
||||
{
|
||||
role: "user",
|
||||
content:
|
||||
`Please summarize the article in one sentence as short as possible: ${content.slice(0, 2000)
|
||||
`Please summarize the article in one sentence as short as possible: ${
|
||||
content.slice(0, 2000)
|
||||
}`,
|
||||
},
|
||||
],
|
||||
@@ -102,7 +103,8 @@ export async function createGenres(
|
||||
{
|
||||
role: "system",
|
||||
content:
|
||||
`you create some keywords that can be used in a recommendation system. The keywords are based on a ${type} description or title. If you do not know the title, take into account the description aswell. Create a range of keywords from very specific ones that describe the general vibe. ${title ? `The name of the ${type} is ${title}` : ""
|
||||
`you create some keywords that can be used in a recommendation system. The keywords are based on a ${type} description or title. If you do not know the title, take into account the description aswell. Create a range of keywords from very specific ones that describe the general vibe. ${
|
||||
title ? `The name of the ${type} is ${title}` : ""
|
||||
}. Return a list of around 20 keywords seperated by commas`,
|
||||
},
|
||||
{
|
||||
@@ -166,7 +168,8 @@ export const getMovieRecommendations = async (
|
||||
|
||||
${keywords}
|
||||
|
||||
The movies should be similar to but not include ${exclude.join(", ")
|
||||
The movies should be similar to but not include ${
|
||||
exclude.join(", ")
|
||||
} or remakes of that.
|
||||
|
||||
respond with a plain unordered list each item starting with the year the movie was released and then the title of the movie seperated by a -`,
|
||||
@@ -213,7 +216,7 @@ export async function createTags(content: string) {
|
||||
|
||||
export async function extractRecipe(content: string) {
|
||||
if (!openAI) return;
|
||||
const completion = await openAI.beta.chat.completions.parse({
|
||||
const completion = await openAI.chat.completions.parse({
|
||||
model: model,
|
||||
temperature: 0.1,
|
||||
messages: [
|
||||
@@ -231,7 +234,7 @@ export async function extractRecipe(content: string) {
|
||||
|
||||
export async function extractArticleMetadata(content: string) {
|
||||
if (!openAI) return;
|
||||
const completion = await openAI.beta.chat.completions.parse({
|
||||
const completion = await openAI.chat.completions.parse({
|
||||
model: model,
|
||||
temperature: 0.1,
|
||||
messages: [
|
||||
@@ -256,7 +259,7 @@ export async function transcribe(
|
||||
): Promise<string | undefined> {
|
||||
if (!openAI) return;
|
||||
|
||||
const file = new File([mp3Data], "audio.mp3", {
|
||||
const file = await toFile(mp3Data, "audio.mp3", {
|
||||
type: "audio/mpeg",
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
parseIngredient,
|
||||
unitsOfMeasure as _unitsOfMeasure,
|
||||
} from "npm:parse-ingredient";
|
||||
} from "parse-ingredient";
|
||||
import { Ingredient, IngredientGroup } from "@lib/recipeSchema.ts";
|
||||
import { removeMarkdownFormatting } from "@lib/string.ts";
|
||||
|
||||
@@ -77,7 +77,7 @@ export function parseIngredients(
|
||||
};
|
||||
|
||||
const unit = ingredient.unit.toLowerCase() as keyof typeof unitsOfMeasure;
|
||||
if (unit in unitsOfMeasure && unit !== "cup") {
|
||||
if (unit in unitsOfMeasure) {
|
||||
ingredient.unit = unitsOfMeasure[unit].short;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ import * as openai from "@lib/openai.ts";
|
||||
import * as tmdb from "@lib/tmdb.ts";
|
||||
import { parseRating } from "@lib/helpers.ts";
|
||||
import { createCache } from "@lib/cache.ts";
|
||||
import { GenericResource, ReviewResource } from "./marka/schema.ts";
|
||||
import { ReviewResource } from "./marka/schema.ts";
|
||||
|
||||
type RecommendationResource = {
|
||||
export type RecommendationResource = {
|
||||
id: string;
|
||||
type: string;
|
||||
rating: number;
|
||||
@@ -96,5 +96,5 @@ export async function getAllRecommendations(): Promise<
|
||||
> {
|
||||
const keys = cache.keys();
|
||||
const res = await Promise.all(keys.map((k) => cache.get(k)));
|
||||
return res.map((r) => JSON.parse(r));
|
||||
return res.filter((s) => !!s).map((r) => JSON.parse(r));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { resources } from "@lib/resources.ts";
|
||||
import fuzzysort from "npm:fuzzysort";
|
||||
import fuzzysort from "fuzzysort";
|
||||
import { extractHashTags } from "@lib/string.ts";
|
||||
import { listResources } from "./marka/index.ts";
|
||||
import { GenericResource } from "./marka/schema.ts";
|
||||
import { parseRating } from "./helpers.ts";
|
||||
|
||||
type ResourceType = keyof typeof resources;
|
||||
|
||||
@@ -72,8 +73,8 @@ export async function searchResource(
|
||||
|
||||
if (
|
||||
!(resource.name in results) &&
|
||||
rating && resource?.content?.reviewRating &&
|
||||
resource.content?.reviewRating?.ratingValue >= rating
|
||||
rating && resource.content.reviewRating?.ratingValue &&
|
||||
parseRating(resource.content.reviewRating.ratingValue) >= rating
|
||||
) {
|
||||
results[resource.name] = resource;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { resources } from "@lib/resources.ts";
|
||||
|
||||
export function formatDate(date: Date): string {
|
||||
const options = { year: "numeric", month: "long", day: "numeric" } as const;
|
||||
return new Intl.DateTimeFormat("en-US", options).format(date);
|
||||
|
||||
@@ -48,8 +48,9 @@ export async function endTask(chatId: string): Promise<string | null> {
|
||||
finalNote += "**[Voice message could not be transcribed]**\n\n";
|
||||
}
|
||||
} else if (entry.type === "photo") {
|
||||
const photoUrl = `${task.noteName.replace(/\.md$/, "")
|
||||
}/photo-${photoIndex++}.jpg`;
|
||||
const photoUrl = `${
|
||||
task.noteName.replace(/\.md$/, "")
|
||||
}/photo-${photoIndex++}.jpg`;
|
||||
|
||||
finalNote += `**Photo**:\n ${photoUrl}\n\n`;
|
||||
photoTasks.push({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GenericResource, GenericResourceSchema } from "./marka/schema.ts";
|
||||
import { GenericResource } from "./marka/schema.ts";
|
||||
|
||||
export interface TMDBMovie {
|
||||
adult: boolean;
|
||||
@@ -39,7 +39,7 @@ export interface GiteaOauthUser {
|
||||
preferred_username: string;
|
||||
email: string;
|
||||
picture: string;
|
||||
groups: any;
|
||||
groups: unknown;
|
||||
}
|
||||
|
||||
export type SearchResult = {
|
||||
|
||||
@@ -11,12 +11,14 @@ export function absolutizeDomUrls(dom: JSDOM, domain: string): void {
|
||||
const base = toBase(domain);
|
||||
|
||||
const rewrite = (selector: string, attr: string) => {
|
||||
document.querySelectorAll<HTMLElement>(selector).forEach((el) => {
|
||||
const v = el.getAttribute(attr);
|
||||
if (!v) return;
|
||||
const abs = toAbsolute(v, base);
|
||||
if (abs !== v) el.setAttribute(attr, abs);
|
||||
});
|
||||
document.querySelectorAll<HTMLElement>(selector).forEach(
|
||||
(el: HTMLElement) => {
|
||||
const v = el.getAttribute(attr);
|
||||
if (!v) return;
|
||||
const abs = toAbsolute(v, base);
|
||||
if (abs !== v) el.setAttribute(attr, abs);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
// Common URL attributes
|
||||
@@ -41,35 +43,35 @@ export function absolutizeDomUrls(dom: JSDOM, domain: string): void {
|
||||
rewrite("form[action]", "action");
|
||||
rewrite("video[poster]", "poster");
|
||||
|
||||
// srcset (img, source)
|
||||
document
|
||||
.querySelectorAll<HTMLElement>("img[srcset], source[srcset]")
|
||||
.forEach((el) => {
|
||||
.querySelectorAll("img[srcset], source[srcset]")
|
||||
.forEach((el: HTMLImageElement) => {
|
||||
const v = el.getAttribute("srcset");
|
||||
if (!v) return;
|
||||
const abs = absolutizeSrcset(v, base);
|
||||
if (abs !== v) el.setAttribute("srcset", abs);
|
||||
});
|
||||
|
||||
// Inline CSS in style attributes: url(...)
|
||||
document.querySelectorAll<HTMLElement>("[style]").forEach((el) => {
|
||||
const v = el.getAttribute("style");
|
||||
if (!v) return;
|
||||
const abs = absolutizeCssUrls(v, base);
|
||||
if (abs !== v) el.setAttribute("style", abs);
|
||||
});
|
||||
document.querySelectorAll("[style]").forEach(
|
||||
(el: HTMLElement) => {
|
||||
const v = el.getAttribute("style");
|
||||
if (!v) return;
|
||||
const abs = absolutizeCssUrls(v, base);
|
||||
if (abs !== v) el.setAttribute("style", abs);
|
||||
},
|
||||
);
|
||||
|
||||
// <style> blocks (inline CSS): url(...)
|
||||
document.querySelectorAll<HTMLStyleElement>("style").forEach((styleEl) => {
|
||||
const css = styleEl.textContent ?? "";
|
||||
const abs = absolutizeCssUrls(css, base);
|
||||
if (abs !== css) styleEl.textContent = abs;
|
||||
});
|
||||
document.querySelectorAll("style").forEach(
|
||||
(styleEl: HTMLStyleElement) => {
|
||||
const css = styleEl.textContent ?? "";
|
||||
const abs = absolutizeCssUrls(css, base);
|
||||
if (abs !== css) styleEl.textContent = abs;
|
||||
},
|
||||
);
|
||||
|
||||
// <meta http-equiv="refresh" content="5; url=/path">
|
||||
document
|
||||
.querySelectorAll<HTMLMetaElement>('meta[http-equiv="refresh" i][content]')
|
||||
.forEach((meta) => {
|
||||
.querySelectorAll('meta[http-equiv="refresh" i][content]')
|
||||
.forEach((meta: HTMLMetaElement) => {
|
||||
const content = meta.getAttribute("content") || "";
|
||||
const abs = absolutizeMetaRefresh(content, base);
|
||||
if (abs !== content) meta.setAttribute("content", abs);
|
||||
|
||||
@@ -7,7 +7,7 @@ export default function Error404() {
|
||||
<Head>
|
||||
<title>404 - Page not found</title>
|
||||
</Head>
|
||||
<MainLayout>
|
||||
<MainLayout url="">
|
||||
<div class="px-8 text-white mt-10">
|
||||
<div class="max-w-screen-md mx-auto flex flex-col items-center justify-center">
|
||||
<h1 class="text-4xl font-bold">404 - Page not found</h1>
|
||||
|
||||
@@ -16,7 +16,6 @@ export const handler: Handlers = {
|
||||
if (!("session" in ctx.state)) {
|
||||
throw new AccessDeniedError();
|
||||
}
|
||||
console.log({ logs });
|
||||
return ctx.render({
|
||||
logs: logs.map((l) => {
|
||||
return {
|
||||
@@ -30,7 +29,7 @@ export const handler: Handlers = {
|
||||
|
||||
function LogLine(
|
||||
{ log }: {
|
||||
log: Log;
|
||||
log: Log & { html?: string };
|
||||
},
|
||||
) {
|
||||
return (
|
||||
@@ -42,7 +41,7 @@ function LogLine(
|
||||
<span class="bg-gray-600 py-1 px-2 text-xs rounded-xl text-white">
|
||||
{log.date.getHours().toString().padStart(2, "0")}:{log.date
|
||||
.getMinutes().toString().padStart(2, "0")}:{log.date.getSeconds()
|
||||
.toString().padStart(2, "0")} {formatDate(log.date)}
|
||||
.toString().padStart(2, "0")} {formatDate(log.date)}
|
||||
</span>
|
||||
<span class="bg-gray-600 py-1 px-2 text-xs rounded-xl text-white">
|
||||
{log.scope}
|
||||
@@ -53,7 +52,8 @@ function LogLine(
|
||||
</div>
|
||||
<div
|
||||
class="text-white"
|
||||
dangerouslySetInnerHTML={{ __html: log.html }}
|
||||
// deno-lint-ignore react-no-danger
|
||||
dangerouslySetInnerHTML={{ __html: log.html ?? "" }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -46,7 +46,7 @@ async function processCreateArticle(
|
||||
const title = result?.title || aiMeta?.headline || "";
|
||||
const id = toUrlSafeString(title);
|
||||
|
||||
const newArticle: Article = {
|
||||
const newArticle: ArticleResource["content"] = {
|
||||
_type: "Article",
|
||||
headline: title,
|
||||
articleBody: result.content,
|
||||
|
||||
@@ -60,12 +60,13 @@ function parseParams(reqUrl: URL): ImageParams | string {
|
||||
}
|
||||
}
|
||||
// Helper function to generate ETag
|
||||
async function generateETag(content: ArrayBuffer): Promise<string> {
|
||||
async function generateETag(content: Uint8Array<ArrayBuffer>): Promise<string> {
|
||||
const hashBuffer = await crypto.subtle.digest("SHA-256", content);
|
||||
return `"${Array.from(new Uint8Array(hashBuffer))
|
||||
return `"${
|
||||
Array.from(new Uint8Array(hashBuffer))
|
||||
.map((b) => b.toString(16).padStart(2, "0"))
|
||||
.join("")
|
||||
}"`;
|
||||
}"`;
|
||||
}
|
||||
|
||||
async function GET(req: Request, _ctx: FreshContext): Promise<Response> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { FreshContext, Handlers } from "$fresh/server.ts";
|
||||
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
|
||||
import * as tmdb from "@lib/tmdb.ts";
|
||||
import { isString, safeFileName } from "@lib/string.ts";
|
||||
import { formatDate, isString, safeFileName } from "@lib/string.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
import {
|
||||
AccessDeniedError,
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
} from "@lib/errors.ts";
|
||||
import { createRecommendationResource } from "@lib/recommendation.ts";
|
||||
import { createResource, fetchResource } from "@lib/marka/index.ts";
|
||||
import { ReviewResource } from "@lib/marka/schema.ts";
|
||||
|
||||
const POST = async (
|
||||
req: Request,
|
||||
@@ -20,7 +21,9 @@ const POST = async (
|
||||
throw new AccessDeniedError();
|
||||
}
|
||||
|
||||
const movie = await fetchResource(`movies/${ctx.params.name}`);
|
||||
const movie = await fetchResource<ReviewResource>(
|
||||
`movies/${ctx.params.name}`,
|
||||
);
|
||||
if (!movie) {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
@@ -33,27 +36,28 @@ const POST = async (
|
||||
}
|
||||
|
||||
const movieDetails = await tmdb.getMovie(tmdbId);
|
||||
const movieCredits = !movie.meta?.author &&
|
||||
const movieCredits = !movie.content?.author &&
|
||||
await tmdb.getMovieCredits(tmdbId);
|
||||
|
||||
const releaseDate = movieDetails.release_date;
|
||||
if (releaseDate && !movie.meta?.date) {
|
||||
movie.meta = movie.meta || {};
|
||||
movie.meta.date = new Date(releaseDate);
|
||||
if (releaseDate && !movie.content?.datePublished) {
|
||||
movie.content = movie.content || {};
|
||||
movie.content.datePublished = formatDate(new Date(releaseDate));
|
||||
}
|
||||
|
||||
const director = movieCredits?.crew?.filter?.((person) =>
|
||||
person.job === "Director"
|
||||
)[0];
|
||||
if (director && !movie.meta?.author) {
|
||||
movie.meta = movie.meta || {};
|
||||
movie.meta.author = director.name;
|
||||
const director = movieCredits &&
|
||||
movieCredits?.crew?.filter?.((person) => person.job === "Director")[0];
|
||||
if (director && !movie.content?.author) {
|
||||
movie.content = movie.content || {};
|
||||
movie.content.author = {
|
||||
_type: "Person",
|
||||
name: director.name,
|
||||
};
|
||||
}
|
||||
|
||||
if (movieDetails.genres) {
|
||||
movie.tags = [
|
||||
movie.content.keywords = [
|
||||
...new Set([
|
||||
...(movie.tags?.map((g) => g.toLowerCase()) || []),
|
||||
...(movie.content.keywords?.map((g) => g.toLowerCase()) || []),
|
||||
...movieDetails.genres.map((g) =>
|
||||
g.name?.toLowerCase().replaceAll(" ", "-")
|
||||
),
|
||||
@@ -61,22 +65,22 @@ const POST = async (
|
||||
];
|
||||
}
|
||||
|
||||
if (!movie.id) {
|
||||
movie.id = tmdbId;
|
||||
if (!movie.name) {
|
||||
movie.name = tmdbId;
|
||||
}
|
||||
|
||||
let finalPath = "";
|
||||
const posterPath = movieDetails.poster_path;
|
||||
if (posterPath && !movie.meta?.image) {
|
||||
if (posterPath && !movie.content?.image) {
|
||||
const poster = await tmdb.getMoviePoster(posterPath);
|
||||
const extension = fileExtension(posterPath);
|
||||
finalPath = `movies/images/${safeFileName(name)}_cover.${extension}`;
|
||||
await createResource(finalPath, poster);
|
||||
movie.meta = movie.meta || {};
|
||||
movie.meta.image = finalPath;
|
||||
movie.content = movie.content || {};
|
||||
movie.content.image = finalPath;
|
||||
}
|
||||
|
||||
await createResource(`movies/${safeFileName(movie.id)}.md`, movie);
|
||||
await createResource(`movies/${safeFileName(movie.name)}.md`, movie);
|
||||
|
||||
createRecommendationResource(movie, movieDetails.overview);
|
||||
|
||||
|
||||
@@ -48,7 +48,14 @@ async function processCreateRecipeFromUrl(
|
||||
}
|
||||
|
||||
if (!recipe) {
|
||||
recipe = await openai.extractRecipe(result.content);
|
||||
const res = await openai.extractRecipe(result.content);
|
||||
if (!res || "errorMessages" in res) {
|
||||
const errorMessage = res?.errorMessages?.[0] ||
|
||||
"could not extract recipe";
|
||||
streamResponse.enqueue(`failed to extract recipe: ${errorMessage}`);
|
||||
return;
|
||||
}
|
||||
recipe = res;
|
||||
}
|
||||
|
||||
const id = safeFileName(recipe?.name || "");
|
||||
@@ -70,8 +77,9 @@ async function processCreateRecipeFromUrl(
|
||||
|
||||
if (newRecipe?.image && newRecipe.image.length > 5) {
|
||||
const extension = fileExtension(new URL(newRecipe.image).pathname);
|
||||
const finalPath = `resources/recipes/images/${safeFileName(id)
|
||||
}_cover.${extension}`;
|
||||
const finalPath = `resources/recipes/images/${
|
||||
safeFileName(id)
|
||||
}_cover.${extension}`;
|
||||
streamResponse.enqueue("downloading image");
|
||||
try {
|
||||
streamResponse.enqueue("downloading image");
|
||||
|
||||
@@ -25,11 +25,14 @@ export function parseJsonLdToRecipeSchema(jsonLdContent: string) {
|
||||
);
|
||||
|
||||
const instructions = Array.isArray(data.recipeInstructions)
|
||||
? data.recipeInstructions.map((instr) => {
|
||||
? data.recipeInstructions.map((instr: unknown) => {
|
||||
if (!instr) return "";
|
||||
if (typeof instr === "string") return instr;
|
||||
if (typeof instr === "object" && instr.text) return instr.text;
|
||||
if (typeof instr === "object" && "text" in instr && instr.text) {
|
||||
return instr.text;
|
||||
}
|
||||
return "";
|
||||
}).filter((instr) => instr.trim() !== "")
|
||||
}).filter((instr: string) => instr.trim() !== "")
|
||||
: [];
|
||||
|
||||
// Parse servings
|
||||
@@ -53,7 +56,7 @@ export function parseJsonLdToRecipeSchema(jsonLdContent: string) {
|
||||
title: data.name || "Unnamed Recipe",
|
||||
image: pickImage(image || data.image || ""),
|
||||
author: Array.isArray(data.author)
|
||||
? data.author.map((a: any) => a.name).join(", ")
|
||||
? data.author.map((a: { name: string }) => a.name).join(", ")
|
||||
: data.author?.name || "",
|
||||
description: data.description || "",
|
||||
ingredients,
|
||||
@@ -81,7 +84,7 @@ function pickImage(images: string | string[]): string {
|
||||
return images;
|
||||
}
|
||||
|
||||
function parseServings(servingsData: any): number {
|
||||
function parseServings(servingsData: unknown): number {
|
||||
if (typeof servingsData === "string") {
|
||||
const match = servingsData.match(/\d+/);
|
||||
return match ? parseInt(match[0], 10) : 1;
|
||||
|
||||
@@ -42,7 +42,8 @@ async function processUpdateRecommendations(
|
||||
}
|
||||
done++;
|
||||
streamResponse.enqueue(
|
||||
`${Math.floor((done / total) * 100)}% [${done + 1
|
||||
`${Math.floor((done / total) * 100)}% [${
|
||||
done + 1
|
||||
}/${total}] ${movie.name}`,
|
||||
);
|
||||
})).catch((err) => {
|
||||
|
||||
@@ -11,7 +11,6 @@ export const handler: Handlers = {
|
||||
}
|
||||
|
||||
const recommendations = await getSimilarMovies(ctx.params.id);
|
||||
console.log({ recommendations });
|
||||
|
||||
return json(recommendations);
|
||||
},
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { FreshContext, Handlers } from "$fresh/server.ts";
|
||||
import { FreshContext, Handlers } from "$fresh/server.ts";
|
||||
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
|
||||
import * as tmdb from "@lib/tmdb.ts";
|
||||
import { safeFileName } from "@lib/string.ts";
|
||||
@@ -37,42 +36,43 @@ const POST = async (
|
||||
}
|
||||
|
||||
const seriesDetails = await tmdb.getSeries(tmdbId);
|
||||
const seriesCredits = !series.meta?.author &&
|
||||
const seriesCredits = !series?.content?.author &&
|
||||
await tmdb.getSeriesCredits(tmdbId);
|
||||
|
||||
const releaseDate = seriesDetails.first_air_date;
|
||||
if (releaseDate && series.meta?.date) {
|
||||
series.meta.date = new Date(releaseDate);
|
||||
if (releaseDate && series.content?.datePublished) {
|
||||
series.content.datePublished = new Date(releaseDate).toISOString();
|
||||
}
|
||||
const posterPath = seriesDetails.poster_path;
|
||||
const director = seriesCredits &&
|
||||
seriesCredits.crew?.filter?.((person) => person.job === "Director")[0] ||
|
||||
seriesCredits.crew?.filter?.((person) => person.job === "Director")[0] ||
|
||||
seriesDetails?.created_by?.[0];
|
||||
if (director && director.name && !series.meta?.author) {
|
||||
series.author = series.author || {};
|
||||
series.author["_type"] = "Person";
|
||||
series.author.name = director.name;
|
||||
if (director && director.name && !series.content?.author) {
|
||||
series.content.author = series.content.author || {
|
||||
_type: "Person",
|
||||
name: director.name,
|
||||
};
|
||||
}
|
||||
|
||||
if (seriesDetails.genres) {
|
||||
series.keywords = [
|
||||
series.content.keywords = [
|
||||
...new Set([
|
||||
...(series.tags?.map((t) => t.toLowerCase()) || []),
|
||||
...(series.content.keywords?.map((t) => t.toLowerCase()) || []),
|
||||
...seriesDetails.genres.map((g) => g.name?.toLowerCase()),
|
||||
].filter(isString)),
|
||||
];
|
||||
}
|
||||
|
||||
let finalPath = "";
|
||||
if (posterPath && !series.meta?.image) {
|
||||
if (posterPath && !series.content?.image) {
|
||||
const poster = await tmdb.getMoviePoster(posterPath);
|
||||
const extension = fileExtension(posterPath);
|
||||
|
||||
finalPath = `series/images/${safeFileName(name)}_cover.${extension}`;
|
||||
await createResource(finalPath, poster);
|
||||
series.image = finalPath;
|
||||
series.content.image = finalPath;
|
||||
}
|
||||
await createResource(`series/${safeFileName(series.id)}.md`, series);
|
||||
await createResource(`series/${safeFileName(series.name)}.md`, series);
|
||||
|
||||
return json(series);
|
||||
};
|
||||
|
||||
@@ -11,28 +11,38 @@ import { Star } from "@components/Stars.tsx";
|
||||
import { MetaTags } from "@components/MetaTags.tsx";
|
||||
import { fetchResource } from "@lib/marka/index.ts";
|
||||
import { ArticleResource } from "@lib/marka/schema.ts";
|
||||
import { parseRating } from "@lib/helpers.ts";
|
||||
|
||||
export const handler: Handlers<{ article: ArticleResource; session: unknown }> = {
|
||||
async GET(_, ctx) {
|
||||
const article = await fetchResource(`articles/${ctx.params.name}.md`);
|
||||
if (!article) {
|
||||
return ctx.renderNotFound();
|
||||
}
|
||||
return ctx.render({ article, session: ctx.state.session });
|
||||
},
|
||||
};
|
||||
export const handler: Handlers<{ article: ArticleResource; session: unknown }> =
|
||||
{
|
||||
async GET(_, ctx) {
|
||||
const article = await fetchResource<ArticleResource>(
|
||||
`articles/${ctx.params.name}.md`,
|
||||
);
|
||||
if (!article) {
|
||||
return ctx.renderNotFound();
|
||||
}
|
||||
return ctx.render({ article, session: ctx.state.session });
|
||||
},
|
||||
};
|
||||
|
||||
export default function Greet(
|
||||
props: PageProps<{ article: Article; session: Record<string, string> }>,
|
||||
props: PageProps<
|
||||
{ article: ArticleResource; session: Record<string, string> }
|
||||
>,
|
||||
) {
|
||||
const { article, session } = props.data;
|
||||
|
||||
const { author = "", date = "", articleBody = "" } = article?.content || {};
|
||||
const { author, datePublished, reviewRating, articleBody = "" } =
|
||||
article?.content || {};
|
||||
|
||||
const content = renderMarkdown(
|
||||
removeImage(articleBody, article.image?.url),
|
||||
);
|
||||
|
||||
const rating = reviewRating?.ratingValue &&
|
||||
parseRating(reviewRating.ratingValue);
|
||||
|
||||
return (
|
||||
<MainLayout
|
||||
url={props.url}
|
||||
@@ -61,36 +71,35 @@ export default function Greet(
|
||||
</PageHero.Title>
|
||||
<PageHero.Subline
|
||||
entries={[
|
||||
author && {
|
||||
title: author,
|
||||
href: `/?q=${encodeURIComponent(author)}`,
|
||||
author?.name && {
|
||||
title: author.name,
|
||||
href: `/?q=${encodeURIComponent(author?.name)}`,
|
||||
},
|
||||
date.toString(),
|
||||
datePublished?.toString(),
|
||||
]}
|
||||
>
|
||||
{article.content.rating && <Star rating={article.content.rating} />}
|
||||
{rating && <Star rating={rating} />}
|
||||
</PageHero.Subline>
|
||||
</PageHero.Footer>
|
||||
</PageHero>
|
||||
{article.content?.tags?.length > 0 && (
|
||||
{article.content?.keywords?.length && (
|
||||
<>
|
||||
<br />
|
||||
<HashTags tags={article.content.tags} />
|
||||
<HashTags tags={article.content.keywords} />
|
||||
</>
|
||||
)}
|
||||
|
||||
<div class="px-8 text-white mt-10">
|
||||
{isYoutubeLink(article.content.url) && (
|
||||
{(article.content.url && isYoutubeLink(article.content.url)) && (
|
||||
<YoutubePlayer link={article.content.url} />
|
||||
)}
|
||||
<pre
|
||||
class="whitespace-break-spaces markdown-body"
|
||||
data-color-mode="dark"
|
||||
data-dark-theme="dark"
|
||||
// deno-lint-ignore react-no-danger
|
||||
dangerouslySetInnerHTML={{ __html: content || "" }}
|
||||
>
|
||||
{content || ""}
|
||||
</pre>
|
||||
/>
|
||||
</div>
|
||||
</MainLayout>
|
||||
);
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||
import { MainLayout } from "@components/layouts/main.tsx";
|
||||
import { type ArticleResource } from "@lib/marka/schema.ts";
|
||||
import { type ArticleResource, GenericResource } from "@lib/marka/schema.ts";
|
||||
import { KMenu } from "@islands/KMenu.tsx";
|
||||
import { Grid } from "@components/Grid.tsx";
|
||||
import { IconArrowLeft } from "@components/icons.tsx";
|
||||
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
||||
import { GenericResource } from "@lib/types.ts";
|
||||
import { ResourceCard } from "@components/Card.tsx";
|
||||
import { Link } from "@islands/Link.tsx";
|
||||
import { listResources } from "@lib/marka/index.ts";
|
||||
@@ -15,7 +14,7 @@ export const handler: Handlers<
|
||||
{ articles: ArticleResource[] | null; searchResults?: GenericResource[] }
|
||||
> = {
|
||||
async GET(req, ctx) {
|
||||
const articles = await listResources("articles");
|
||||
const articles = await listResources<ArticleResource>("articles");
|
||||
const searchParams = parseResourceUrl(req.url);
|
||||
const searchResults = searchParams &&
|
||||
await searchResource({ ...searchParams, types: ["article"] });
|
||||
|
||||
@@ -22,10 +22,11 @@ export default function Home(props: PageProps) {
|
||||
<Card
|
||||
title={`${m.name}`}
|
||||
backgroundSize={80}
|
||||
image={`${m.emoji.endsWith(".png")
|
||||
image={`${
|
||||
m.emoji.endsWith(".png")
|
||||
? `/emojis/${encodeURIComponent(m.emoji)}`
|
||||
: "/placeholder.svg"
|
||||
}`}
|
||||
}`}
|
||||
link={m.link}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PageProps, RouteContext } from "$fresh/server.ts";
|
||||
import { MainLayout } from "@components/layouts/main.tsx";
|
||||
import { ReviewResource, ReviewSchema } from "@lib/marka/schema.ts";
|
||||
import { ReviewResource } from "@lib/marka/schema.ts";
|
||||
import { removeImage, renderMarkdown } from "@lib/markdown.ts";
|
||||
import { KMenu } from "@islands/KMenu.tsx";
|
||||
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||
@@ -24,12 +24,16 @@ export default async function Greet(
|
||||
return ctx.renderNotFound();
|
||||
}
|
||||
|
||||
const { author = "", datePublished = "",reviewBody } = movie.content;
|
||||
const { author, datePublished, reviewBody = "", reviewRating } =
|
||||
movie.content;
|
||||
|
||||
const content = renderMarkdown(
|
||||
removeImage(reviewBody || "", movie.content.image),
|
||||
removeImage(reviewBody, movie.content.image),
|
||||
);
|
||||
|
||||
const rating = reviewRating?.ratingValue &&
|
||||
parseRating(reviewRating.ratingValue);
|
||||
|
||||
return (
|
||||
<MainLayout url={props.url} title={`Movie > ${movie.name}`} context={movie}>
|
||||
<RedirectSearchHandler />
|
||||
@@ -53,37 +57,33 @@ export default async function Greet(
|
||||
</PageHero.Title>
|
||||
<PageHero.Subline
|
||||
entries={[
|
||||
author && {
|
||||
title: author?.name,
|
||||
author?.name &&
|
||||
{
|
||||
title: author.name,
|
||||
href: `/?q=${encodeURIComponent(author?.name)}`,
|
||||
},
|
||||
date.toString(),
|
||||
datePublished?.toString(),
|
||||
]}
|
||||
>
|
||||
{movie.content.reviewRating && (
|
||||
<Star
|
||||
rating={parseRating(movie.content?.reviewRating?.ratingValue)}
|
||||
/>
|
||||
)}
|
||||
{rating && <Star rating={rating} />}
|
||||
</PageHero.Subline>
|
||||
</PageHero.Footer>
|
||||
</PageHero>
|
||||
{false && (
|
||||
{movie.name && (
|
||||
<Recommendations
|
||||
id={movie.id}
|
||||
id={movie.name}
|
||||
type="movie"
|
||||
/>
|
||||
)}
|
||||
<div class="px-8 text-white mt-10">
|
||||
{movie?.content?.reviewBody?.length > 80
|
||||
? <h2 class="text-4xl font-bold mb-4">Review</h2>
|
||||
: <></>}
|
||||
{reviewBody?.length > 80 && (
|
||||
<h2 class="text-4xl font-bold mb-4">Review</h2>
|
||||
)}
|
||||
<pre
|
||||
class="whitespace-break-spaces"
|
||||
// deno-lint-ignore react-no-danger
|
||||
dangerouslySetInnerHTML={{ __html: content || "" }}
|
||||
>
|
||||
{content}
|
||||
</pre>
|
||||
/>
|
||||
</div>
|
||||
</MainLayout>
|
||||
);
|
||||
|
||||
@@ -1,29 +1,33 @@
|
||||
import { MainLayout } from "@components/layouts/main.tsx";
|
||||
import { ReviewResource } from "@lib/marka/schema.ts";
|
||||
import { GenericResource, ReviewResource } from "@lib/marka/schema.ts";
|
||||
import { ResourceCard } from "@components/Card.tsx";
|
||||
import { Grid } from "@components/Grid.tsx";
|
||||
import { IconArrowLeft } from "@components/icons.tsx";
|
||||
import { KMenu } from "@islands/KMenu.tsx";
|
||||
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||
import { GenericResource } from "@lib/types.ts";
|
||||
import { PageProps } from "$fresh/server.ts";
|
||||
import { listResources } from "@lib/marka/index.ts";
|
||||
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
||||
import { parseRating } from "@lib/helpers.ts";
|
||||
|
||||
function sortOptional(a: number | string = 0, b: number | string = 0) {
|
||||
return (parseRating(a) > parseRating(b)) ? 1 : -1;
|
||||
}
|
||||
|
||||
export default async function MovieIndex(
|
||||
props: PageProps<
|
||||
{ movies: ReviewResource[] | null; searchResults: GenericResource[] }
|
||||
>,
|
||||
) {
|
||||
const allMovies = await listResources("movies");
|
||||
const allMovies = await listResources<ReviewResource>("movies");
|
||||
const searchParams = parseResourceUrl(props.url);
|
||||
const searchResults = searchParams &&
|
||||
await searchResource({ ...searchParams, types: ["movie"] });
|
||||
const movies = allMovies.sort((a, b) =>
|
||||
a?.content?.reviewRating?.ratingValue >
|
||||
b?.content?.reviewRating?.ratingValue
|
||||
? -1
|
||||
: 1
|
||||
sortOptional(
|
||||
a.content.reviewRating?.ratingValue,
|
||||
b.content.reviewRating?.ratingValue,
|
||||
)
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -13,13 +13,16 @@ import { MetaTags } from "@components/MetaTags.tsx";
|
||||
import { fetchResource } from "@lib/marka/index.ts";
|
||||
import { RecipeResource } from "@lib/marka/schema.ts";
|
||||
import { parseIngredients } from "@lib/parseIngredient.ts";
|
||||
import { parseRating } from "@lib/helpers.ts";
|
||||
|
||||
export const handler: Handlers<
|
||||
{ recipe: RecipeResource; session: unknown } | null
|
||||
> = {
|
||||
async GET(_, ctx) {
|
||||
try {
|
||||
const recipe = await fetchResource(`recipes/${ctx.params.name}.md`);
|
||||
const recipe = await fetchResource<RecipeResource>(
|
||||
`recipes/${ctx.params.name}.md`,
|
||||
);
|
||||
if (!recipe) {
|
||||
return ctx.renderNotFound();
|
||||
}
|
||||
@@ -36,7 +39,7 @@ function ValidRecipe({
|
||||
portion,
|
||||
}: { recipe: RecipeResource; amount: Signal<number>; portion: number }) {
|
||||
const ingredients = parseIngredients(
|
||||
recipe.content.recipeIngredient?.join("\n"),
|
||||
recipe.content.recipeIngredient?.join("\n") || "",
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -54,10 +57,12 @@ function ValidRecipe({
|
||||
<div class="pl-2">
|
||||
<ol class="list-decimal grid gap-4">
|
||||
{recipe.content.recipeInstructions &&
|
||||
(recipe.content.recipeInstructions.filter((inst) => !!inst?.length)
|
||||
(recipe.content.recipeInstructions
|
||||
.filter((inst) => !!inst?.length)
|
||||
.map((instruction) => {
|
||||
return (
|
||||
<li
|
||||
// deno-lint-ignore react-no-danger
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: renderMarkdown(instruction),
|
||||
}}
|
||||
@@ -71,17 +76,20 @@ function ValidRecipe({
|
||||
}
|
||||
|
||||
export default function Page(
|
||||
props: PageProps<{ recipe: Recipe; session: Record<string, string> }>,
|
||||
props: PageProps<{ recipe: RecipeResource; session: Record<string, string> }>,
|
||||
) {
|
||||
const { recipe, session } = props.data;
|
||||
|
||||
const portion = recipe.recipeYield;
|
||||
const portion = recipe.content.recipeYield;
|
||||
const amount = useSignal(portion || 1);
|
||||
|
||||
const subline = [
|
||||
recipe?.content?.prepTime && `Duration ${recipe?.content?.prepTime}`,
|
||||
recipe?.content?.totalTime && `Duration ${recipe?.content?.totalTime}`,
|
||||
].filter(Boolean) as string[];
|
||||
|
||||
const rating = recipe.content.reviewRating?.ratingValue &&
|
||||
parseRating(recipe.content.reviewRating.ratingValue);
|
||||
|
||||
return (
|
||||
<MainLayout
|
||||
url={props.url}
|
||||
@@ -105,13 +113,13 @@ export default function Page(
|
||||
)}
|
||||
</PageHero.Header>
|
||||
<PageHero.Footer>
|
||||
<PageHero.Title link={recipe.content?.link}>
|
||||
<PageHero.Title link={recipe.content?.url}>
|
||||
{recipe.content.name}
|
||||
</PageHero.Title>
|
||||
<PageHero.Subline
|
||||
entries={subline}
|
||||
>
|
||||
{recipe.meta?.rating && <Star rating={recipe.meta?.rating} />}
|
||||
{rating && <Star rating={rating} />}
|
||||
</PageHero.Subline>
|
||||
</PageHero.Footer>
|
||||
</PageHero>
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||
import { MainLayout } from "@components/layouts/main.tsx";
|
||||
import { Recipe } from "@lib/recipeSchema.ts";
|
||||
import { Grid } from "@components/Grid.tsx";
|
||||
import { IconArrowLeft } from "@components/icons.tsx";
|
||||
import { KMenu } from "@islands/KMenu.tsx";
|
||||
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||
import { GenericResource } from "@lib/types.ts";
|
||||
import { ResourceCard } from "@components/Card.tsx";
|
||||
import { fetchResource, listResources } from "@lib/marka/index.ts";
|
||||
import { listResources } from "@lib/marka/index.ts";
|
||||
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
||||
import { GenericResource, RecipeResource } from "@lib/marka/schema.ts";
|
||||
|
||||
export const handler: Handlers<
|
||||
{ recipes: Recipe[] | null; searchResults?: GenericResource[] }
|
||||
{ recipes: RecipeResource[] | null; searchResults?: GenericResource[] }
|
||||
> = {
|
||||
async GET(req, ctx) {
|
||||
const recipes = await listResources("recipes");
|
||||
const recipes = await listResources<RecipeResource>("recipes");
|
||||
const searchParams = parseResourceUrl(req.url);
|
||||
const searchResults = searchParams &&
|
||||
await searchResource({ ...searchParams, types: ["recipe"] });
|
||||
@@ -24,7 +23,7 @@ export const handler: Handlers<
|
||||
|
||||
export default function Greet(
|
||||
props: PageProps<
|
||||
{ recipes: Recipe[] | null; searchResults: GenericResource[] }
|
||||
{ recipes: RecipeResource[] | null; searchResults: GenericResource[] }
|
||||
>,
|
||||
) {
|
||||
const { recipes, searchResults } = props.data;
|
||||
|
||||
@@ -13,7 +13,9 @@ import { ReviewResource } from "@lib/marka/schema.ts";
|
||||
|
||||
export const handler: Handlers<{ serie: ReviewResource; session: unknown }> = {
|
||||
async GET(_, ctx) {
|
||||
const serie = await fetchResource(`series/${ctx.params.name}.md`);
|
||||
const serie = await fetchResource<ReviewResource>(
|
||||
`series/${ctx.params.name}.md`,
|
||||
);
|
||||
|
||||
if (!serie) {
|
||||
return ctx.renderNotFound();
|
||||
@@ -27,16 +29,19 @@ export default function Greet(
|
||||
) {
|
||||
const { serie, session } = props.data;
|
||||
|
||||
const { author = "", date = "", reviewBody } = serie?.content || {};
|
||||
const { author, datePublished, reviewBody = "" } = serie?.content || {};
|
||||
|
||||
const content = renderMarkdown(
|
||||
removeImage(reviewBody, serie.image?.url),
|
||||
);
|
||||
|
||||
const rating = serie.content.reviewRating?.ratingValue &&
|
||||
parseRating(serie.content.reviewRating.ratingValue);
|
||||
|
||||
return (
|
||||
<MainLayout
|
||||
url={props.url}
|
||||
title={`Serie > ${serie.content?.name}`}
|
||||
title={`Serie > ${serie.content?.itemReviewed?.name}`}
|
||||
context={serie}
|
||||
>
|
||||
<RedirectSearchHandler />
|
||||
@@ -59,37 +64,33 @@ export default function Greet(
|
||||
<PageHero.Title>{serie.name}</PageHero.Title>
|
||||
<PageHero.Subline
|
||||
entries={[
|
||||
author && {
|
||||
title: author,
|
||||
href: `/?q=${encodeURIComponent(author)}`,
|
||||
author?.name &&
|
||||
{
|
||||
title: author.name,
|
||||
href: `/?q=${encodeURIComponent(author?.name)}`,
|
||||
},
|
||||
date.toString(),
|
||||
datePublished?.toString(),
|
||||
]}
|
||||
>
|
||||
{serie.content?.reviewRating && (
|
||||
<Star
|
||||
rating={parseRating(serie.content?.reviewRating?.ratingValue)}
|
||||
/>
|
||||
)}
|
||||
{rating && <Star rating={rating} />}
|
||||
</PageHero.Subline>
|
||||
</PageHero.Footer>
|
||||
</PageHero>
|
||||
{serie.content?.tags?.length > 0 && (
|
||||
{serie.content?.keywords?.length && (
|
||||
<>
|
||||
<br />
|
||||
<HashTags tags={serie.content?.tags} />
|
||||
<HashTags tags={serie.content?.keywords} />
|
||||
</>
|
||||
)}
|
||||
<div class="px-8 text-white mt-10">
|
||||
{serie?.content?.reviewBody?.length > 80
|
||||
? <h2 class="text-4xl font-bold mb-4">Review</h2>
|
||||
: <></>}
|
||||
{serie?.content?.reviewBody?.length && (
|
||||
<h2 class="text-4xl font-bold mb-4">Review</h2>
|
||||
)}
|
||||
<pre
|
||||
class="whitespace-break-spaces"
|
||||
// deno-lint-ignore react-no-danger
|
||||
dangerouslySetInnerHTML={{ __html: content || "" }}
|
||||
>
|
||||
{content}
|
||||
</pre>
|
||||
/>
|
||||
</div>
|
||||
</MainLayout>
|
||||
);
|
||||
|
||||
@@ -13,7 +13,7 @@ export const handler: Handlers<
|
||||
{ series: ReviewResource[] | null; searchResults?: GenericResource[] }
|
||||
> = {
|
||||
async GET(req, ctx) {
|
||||
const series = await listResources("series");
|
||||
const series = await listResources<ReviewResource>("series");
|
||||
const searchParams = parseResourceUrl(req.url);
|
||||
const searchResults = searchParams &&
|
||||
await searchResource({ ...searchParams, types: ["series"] });
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<browserconfig>
|
||||
<msapplication>
|
||||
<tile>
|
||||
<square150x150logo src="/mstile-150x150.png"/>
|
||||
<TileColor>#da532c</TileColor>
|
||||
</tile>
|
||||
</msapplication>
|
||||
<msapplication>
|
||||
<tile>
|
||||
<square150x150logo src="/mstile-150x150.png" />
|
||||
<TileColor>#da532c</TileColor>
|
||||
</tile>
|
||||
</msapplication>
|
||||
</browserconfig>
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,6 +1,19 @@
|
||||
<svg width="40" height="40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M34.092 8.845C38.929 20.652 34.092 27 30 30.5c1 3.5-2.986 4.222-4.5 2.5-4.457 1.537-13.512 1.487-20-5C2 24.5 4.73 16.714 14 11.5c8-4.5 16-7 20.092-2.655Z" fill="#FFDB1E"/>
|
||||
<path d="M14 11.5c6.848-4.497 15.025-6.38 18.368-3.47C37.5 12.5 21.5 22.612 15.5 25c-6.5 2.587-3 8.5-6.5 8.5-3 0-2.5-4-5.183-7.75C2.232 23.535 6.16 16.648 14 11.5Z" fill="#fff" stroke="#FFDB1E"/>
|
||||
<path d="M28.535 8.772c4.645 1.25-.365 5.695-4.303 8.536-3.732 2.692-6.606 4.21-7.923 4.83-.366.173-1.617-2.252-1.617-1 0 .417-.7 2.238-.934 2.326-1.365.512-4.223 1.29-5.835 1.29-3.491 0-1.923-4.754 3.014-9.122.892-.789 1.478-.645 2.283-.645-.537-.773-.534-.917.403-1.546C17.79 10.64 23 8.77 25.212 8.42c.366.014.82.35.82.629.41-.14 2.095-.388 2.503-.278Z" fill="#FFE600"/>
|
||||
<path d="M14.297 16.49c.985-.747 1.644-1.01 2.099-2.526.566.121.841-.08 1.29-.701.324.466 1.657.608 2.453.701-.715.451-1.057.852-1.452 2.106-1.464-.611-3.167-.302-4.39.42Z" fill="#fff"/>
|
||||
<path
|
||||
d="M34.092 8.845C38.929 20.652 34.092 27 30 30.5c1 3.5-2.986 4.222-4.5 2.5-4.457 1.537-13.512 1.487-20-5C2 24.5 4.73 16.714 14 11.5c8-4.5 16-7 20.092-2.655Z"
|
||||
fill="#FFDB1E"
|
||||
/>
|
||||
<path
|
||||
d="M14 11.5c6.848-4.497 15.025-6.38 18.368-3.47C37.5 12.5 21.5 22.612 15.5 25c-6.5 2.587-3 8.5-6.5 8.5-3 0-2.5-4-5.183-7.75C2.232 23.535 6.16 16.648 14 11.5Z"
|
||||
fill="#fff"
|
||||
stroke="#FFDB1E"
|
||||
/>
|
||||
<path
|
||||
d="M28.535 8.772c4.645 1.25-.365 5.695-4.303 8.536-3.732 2.692-6.606 4.21-7.923 4.83-.366.173-1.617-2.252-1.617-1 0 .417-.7 2.238-.934 2.326-1.365.512-4.223 1.29-5.835 1.29-3.491 0-1.923-4.754 3.014-9.122.892-.789 1.478-.645 2.283-.645-.537-.773-.534-.917.403-1.546C17.79 10.64 23 8.77 25.212 8.42c.366.014.82.35.82.629.41-.14 2.095-.388 2.503-.278Z"
|
||||
fill="#FFE600"
|
||||
/>
|
||||
<path
|
||||
d="M14.297 16.49c.985-.747 1.644-1.01 2.099-2.526.566.121.841-.08 1.29-.701.324.466 1.657.608 2.453.701-.715.451-1.057.852-1.452 2.106-1.464-.611-3.167-.302-4.39.42Z"
|
||||
fill="#fff"
|
||||
/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.1 KiB |
@@ -1,7 +1,35 @@
|
||||
<svg width="387" height="387" viewBox="0 0 387 387" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="387" height="387" fill="#2B2930"/>
|
||||
<circle cx="212.471" cy="154.8" r="15.5559" stroke="#39363F" stroke-width="3.03529"/>
|
||||
<path d="M110.978 249.463L155.261 205.18C161.188 199.253 170.797 199.253 176.724 205.18L221.007 249.463" stroke="#39363F" stroke-width="3.03529"/>
|
||||
<path d="M192.362 220.628L207.81 205.18C213.737 199.253 223.346 199.253 229.273 205.18L273.556 249.463" stroke="#39363F" stroke-width="3.03529"/>
|
||||
<rect x="86.1265" y="86.1265" width="214.747" height="214.747" rx="13.6588" stroke="#39363F" stroke-width="3.03529"/>
|
||||
<svg
|
||||
width="387"
|
||||
height="387"
|
||||
viewBox="0 0 387 387"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<rect width="387" height="387" fill="#2B2930" />
|
||||
<circle
|
||||
cx="212.471"
|
||||
cy="154.8"
|
||||
r="15.5559"
|
||||
stroke="#39363F"
|
||||
stroke-width="3.03529"
|
||||
/>
|
||||
<path
|
||||
d="M110.978 249.463L155.261 205.18C161.188 199.253 170.797 199.253 176.724 205.18L221.007 249.463"
|
||||
stroke="#39363F"
|
||||
stroke-width="3.03529"
|
||||
/>
|
||||
<path
|
||||
d="M192.362 220.628L207.81 205.18C213.737 199.253 223.346 199.253 229.273 205.18L273.556 249.463"
|
||||
stroke="#39363F"
|
||||
stroke-width="3.03529"
|
||||
/>
|
||||
<rect
|
||||
x="86.1265"
|
||||
y="86.1265"
|
||||
width="214.747"
|
||||
height="214.747"
|
||||
rx="13.6588"
|
||||
stroke="#39363F"
|
||||
stroke-width="3.03529"
|
||||
/>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 652 B After Width: | Height: | Size: 758 B |
@@ -1,205 +1,205 @@
|
||||
code[class*="language-"],
|
||||
pre[class*="language-"] {
|
||||
text-align: left;
|
||||
white-space: pre;
|
||||
word-spacing: normal;
|
||||
word-break: normal;
|
||||
word-wrap: normal;
|
||||
color: #eee;
|
||||
background: #2f2f2f;
|
||||
font-family: Roboto Mono, monospace;
|
||||
font-size: 1em;
|
||||
line-height: 1.5em;
|
||||
text-align: left;
|
||||
white-space: pre;
|
||||
word-spacing: normal;
|
||||
word-break: normal;
|
||||
word-wrap: normal;
|
||||
color: #eee;
|
||||
background: #2f2f2f;
|
||||
font-family: Roboto Mono, monospace;
|
||||
font-size: 1em;
|
||||
line-height: 1.5em;
|
||||
|
||||
-moz-tab-size: 4;
|
||||
-o-tab-size: 4;
|
||||
tab-size: 4;
|
||||
-moz-tab-size: 4;
|
||||
-o-tab-size: 4;
|
||||
tab-size: 4;
|
||||
|
||||
-webkit-hyphens: none;
|
||||
-moz-hyphens: none;
|
||||
-ms-hyphens: none;
|
||||
hyphens: none;
|
||||
-webkit-hyphens: none;
|
||||
-moz-hyphens: none;
|
||||
-ms-hyphens: none;
|
||||
hyphens: none;
|
||||
}
|
||||
|
||||
code[class*="language-"]::-moz-selection,
|
||||
pre[class*="language-"]::-moz-selection,
|
||||
code[class*="language-"] ::-moz-selection,
|
||||
pre[class*="language-"] ::-moz-selection {
|
||||
background: #363636;
|
||||
background: #363636;
|
||||
}
|
||||
|
||||
code[class*="language-"]::selection,
|
||||
pre[class*="language-"]::selection,
|
||||
code[class*="language-"] ::selection,
|
||||
pre[class*="language-"] ::selection {
|
||||
background: #363636;
|
||||
background: #363636;
|
||||
}
|
||||
|
||||
:not(pre) > code[class*="language-"] {
|
||||
white-space: normal;
|
||||
border-radius: 0.2em;
|
||||
padding: 0.1em;
|
||||
white-space: normal;
|
||||
border-radius: 0.2em;
|
||||
padding: 0.1em;
|
||||
}
|
||||
|
||||
pre[class*="language-"] {
|
||||
overflow: auto;
|
||||
position: relative;
|
||||
margin: 0.5em 0;
|
||||
padding: 1.25em 1em;
|
||||
overflow: auto;
|
||||
position: relative;
|
||||
margin: 0.5em 0;
|
||||
padding: 1.25em 1em;
|
||||
}
|
||||
|
||||
.language-css > code,
|
||||
.language-sass > code,
|
||||
.language-scss > code {
|
||||
color: #fd9170;
|
||||
color: #fd9170;
|
||||
}
|
||||
|
||||
[class*="language-"] .namespace {
|
||||
opacity: 0.7;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.token.atrule {
|
||||
color: #c792ea;
|
||||
color: #c792ea;
|
||||
}
|
||||
|
||||
.token.attr-name {
|
||||
color: #ffcb6b;
|
||||
color: #ffcb6b;
|
||||
}
|
||||
|
||||
.token.attr-value {
|
||||
color: #a5e844;
|
||||
color: #a5e844;
|
||||
}
|
||||
|
||||
.token.attribute {
|
||||
color: #a5e844;
|
||||
color: #a5e844;
|
||||
}
|
||||
|
||||
.token.boolean {
|
||||
color: #c792ea;
|
||||
color: #c792ea;
|
||||
}
|
||||
|
||||
.token.builtin {
|
||||
color: #ffcb6b;
|
||||
color: #ffcb6b;
|
||||
}
|
||||
|
||||
.token.cdata {
|
||||
color: #80cbc4;
|
||||
color: #80cbc4;
|
||||
}
|
||||
|
||||
.token.char {
|
||||
color: #80cbc4;
|
||||
color: #80cbc4;
|
||||
}
|
||||
|
||||
.token.class {
|
||||
color: #ffcb6b;
|
||||
color: #ffcb6b;
|
||||
}
|
||||
|
||||
.token.class-name {
|
||||
color: #f2ff00;
|
||||
color: #f2ff00;
|
||||
}
|
||||
|
||||
.token.comment {
|
||||
color: #616161;
|
||||
color: #616161;
|
||||
}
|
||||
|
||||
.token.constant {
|
||||
color: #c792ea;
|
||||
color: #c792ea;
|
||||
}
|
||||
|
||||
.token.deleted {
|
||||
color: #ff6666;
|
||||
color: #ff6666;
|
||||
}
|
||||
|
||||
.token.doctype {
|
||||
color: #616161;
|
||||
color: #616161;
|
||||
}
|
||||
|
||||
.token.entity {
|
||||
color: #ff6666;
|
||||
color: #ff6666;
|
||||
}
|
||||
|
||||
.token.function {
|
||||
color: #c792ea;
|
||||
color: #c792ea;
|
||||
}
|
||||
|
||||
.token.hexcode {
|
||||
color: #f2ff00;
|
||||
color: #f2ff00;
|
||||
}
|
||||
|
||||
.token.id {
|
||||
color: #c792ea;
|
||||
font-weight: bold;
|
||||
color: #c792ea;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.token.important {
|
||||
color: #c792ea;
|
||||
font-weight: bold;
|
||||
color: #c792ea;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.token.inserted {
|
||||
color: #80cbc4;
|
||||
color: #80cbc4;
|
||||
}
|
||||
|
||||
.token.keyword {
|
||||
color: #c792ea;
|
||||
color: #c792ea;
|
||||
}
|
||||
|
||||
.token.number {
|
||||
color: #fd9170;
|
||||
color: #fd9170;
|
||||
}
|
||||
|
||||
.token.operator {
|
||||
color: #89ddff;
|
||||
color: #89ddff;
|
||||
}
|
||||
|
||||
.token.prolog {
|
||||
color: #616161;
|
||||
color: #616161;
|
||||
}
|
||||
|
||||
.token.property {
|
||||
color: #80cbc4;
|
||||
color: #80cbc4;
|
||||
}
|
||||
|
||||
.token.pseudo-class {
|
||||
color: #a5e844;
|
||||
color: #a5e844;
|
||||
}
|
||||
|
||||
.token.pseudo-element {
|
||||
color: #a5e844;
|
||||
color: #a5e844;
|
||||
}
|
||||
|
||||
.token.punctuation {
|
||||
color: #89ddff;
|
||||
color: #89ddff;
|
||||
}
|
||||
|
||||
.token.regex {
|
||||
color: #f2ff00;
|
||||
color: #f2ff00;
|
||||
}
|
||||
|
||||
.token.selector {
|
||||
color: #ff6666;
|
||||
color: #ff6666;
|
||||
}
|
||||
|
||||
.token.string {
|
||||
color: #a5e844;
|
||||
color: #a5e844;
|
||||
}
|
||||
|
||||
.token.symbol {
|
||||
color: #c792ea;
|
||||
color: #c792ea;
|
||||
}
|
||||
|
||||
.token.tag {
|
||||
color: #ff6666;
|
||||
color: #ff6666;
|
||||
}
|
||||
|
||||
.token.unit {
|
||||
color: #fd9170;
|
||||
color: #fd9170;
|
||||
}
|
||||
|
||||
.token.url {
|
||||
color: #ff6666;
|
||||
color: #ff6666;
|
||||
}
|
||||
|
||||
.token.variable {
|
||||
color: #ff6666;
|
||||
color: #ff6666;
|
||||
}
|
||||
|
||||
@@ -5,95 +5,99 @@
|
||||
*/
|
||||
code[class*="language-"],
|
||||
pre[class*="language-"] {
|
||||
color: white;
|
||||
background: none;
|
||||
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
|
||||
font-size: 1em;
|
||||
text-align: left;
|
||||
text-shadow: 0 -.1em .2em black;
|
||||
white-space: pre;
|
||||
word-spacing: normal;
|
||||
word-break: normal;
|
||||
word-wrap: normal;
|
||||
line-height: 1.5;
|
||||
color: white;
|
||||
background: none;
|
||||
font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
|
||||
font-size: 1em;
|
||||
text-align: left;
|
||||
text-shadow: 0 -0.1em 0.2em black;
|
||||
white-space: pre;
|
||||
word-spacing: normal;
|
||||
word-break: normal;
|
||||
word-wrap: normal;
|
||||
line-height: 1.5;
|
||||
|
||||
-moz-tab-size: 4;
|
||||
-o-tab-size: 4;
|
||||
tab-size: 4;
|
||||
-moz-tab-size: 4;
|
||||
-o-tab-size: 4;
|
||||
tab-size: 4;
|
||||
|
||||
-webkit-hyphens: none;
|
||||
-moz-hyphens: none;
|
||||
-ms-hyphens: none;
|
||||
hyphens: none;
|
||||
-webkit-hyphens: none;
|
||||
-moz-hyphens: none;
|
||||
-ms-hyphens: none;
|
||||
hyphens: none;
|
||||
}
|
||||
|
||||
pre[class*="language-"],
|
||||
:not(pre) > code[class*="language-"] {
|
||||
background: hsl(0, 0%, 8%); /* #141414 */
|
||||
background: hsl(0, 0%, 8%); /* #141414 */
|
||||
}
|
||||
|
||||
/* Code blocks */
|
||||
pre[class*="language-"] {
|
||||
border-radius: .5em;
|
||||
border: .3em solid hsl(0, 0%, 33%); /* #282A2B */
|
||||
box-shadow: 1px 1px .5em black inset;
|
||||
margin: .5em 0;
|
||||
overflow: auto;
|
||||
padding: 1em;
|
||||
border-radius: 0.5em;
|
||||
border: 0.3em solid hsl(0, 0%, 33%); /* #282A2B */
|
||||
box-shadow: 1px 1px 0.5em black inset;
|
||||
margin: 0.5em 0;
|
||||
overflow: auto;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
pre[class*="language-"]::-moz-selection {
|
||||
/* Firefox */
|
||||
background: hsl(200, 4%, 16%); /* #282A2B */
|
||||
/* Firefox */
|
||||
background: hsl(200, 4%, 16%); /* #282A2B */
|
||||
}
|
||||
|
||||
pre[class*="language-"]::selection {
|
||||
/* Safari */
|
||||
background: hsl(200, 4%, 16%); /* #282A2B */
|
||||
/* Safari */
|
||||
background: hsl(200, 4%, 16%); /* #282A2B */
|
||||
}
|
||||
|
||||
/* Text Selection colour */
|
||||
pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
|
||||
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
|
||||
text-shadow: none;
|
||||
background: hsla(0, 0%, 93%, 0.15); /* #EDEDED */
|
||||
pre[class*="language-"]::-moz-selection,
|
||||
pre[class*="language-"] ::-moz-selection,
|
||||
code[class*="language-"]::-moz-selection,
|
||||
code[class*="language-"] ::-moz-selection {
|
||||
text-shadow: none;
|
||||
background: hsla(0, 0%, 93%, 0.15); /* #EDEDED */
|
||||
}
|
||||
|
||||
pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
|
||||
code[class*="language-"]::selection, code[class*="language-"] ::selection {
|
||||
text-shadow: none;
|
||||
background: hsla(0, 0%, 93%, 0.15); /* #EDEDED */
|
||||
pre[class*="language-"]::selection,
|
||||
pre[class*="language-"] ::selection,
|
||||
code[class*="language-"]::selection,
|
||||
code[class*="language-"] ::selection {
|
||||
text-shadow: none;
|
||||
background: hsla(0, 0%, 93%, 0.15); /* #EDEDED */
|
||||
}
|
||||
|
||||
/* Inline code */
|
||||
:not(pre) > code[class*="language-"] {
|
||||
border-radius: .3em;
|
||||
border: .13em solid hsl(0, 0%, 33%); /* #545454 */
|
||||
box-shadow: 1px 1px .3em -.1em black inset;
|
||||
padding: .15em .2em .05em;
|
||||
white-space: normal;
|
||||
border-radius: 0.3em;
|
||||
border: 0.13em solid hsl(0, 0%, 33%); /* #545454 */
|
||||
box-shadow: 1px 1px 0.3em -0.1em black inset;
|
||||
padding: 0.15em 0.2em 0.05em;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.token.comment,
|
||||
.token.prolog,
|
||||
.token.doctype,
|
||||
.token.cdata {
|
||||
color: hsl(0, 0%, 47%); /* #777777 */
|
||||
color: hsl(0, 0%, 47%); /* #777777 */
|
||||
}
|
||||
|
||||
.token.punctuation {
|
||||
opacity: .7;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.token.namespace {
|
||||
opacity: .7;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.token.tag,
|
||||
.token.boolean,
|
||||
.token.number,
|
||||
.token.deleted {
|
||||
color: hsl(14, 58%, 55%); /* #CF6A4C */
|
||||
color: hsl(14, 58%, 55%); /* #CF6A4C */
|
||||
}
|
||||
|
||||
.token.keyword,
|
||||
@@ -102,7 +106,7 @@ code[class*="language-"]::selection, code[class*="language-"] ::selection {
|
||||
.token.constant,
|
||||
.token.symbol,
|
||||
.token.builtin {
|
||||
color: hsl(53, 89%, 79%); /* #F9EE98 */
|
||||
color: hsl(53, 89%, 79%); /* #F9EE98 */
|
||||
}
|
||||
|
||||
.token.attr-name,
|
||||
@@ -116,54 +120,58 @@ code[class*="language-"]::selection, code[class*="language-"] ::selection {
|
||||
.style .token.string,
|
||||
.token.variable,
|
||||
.token.inserted {
|
||||
color: hsl(76, 21%, 52%); /* #8F9D6A */
|
||||
color: hsl(76, 21%, 52%); /* #8F9D6A */
|
||||
}
|
||||
|
||||
.token.atrule {
|
||||
color: hsl(218, 22%, 55%); /* #7587A6 */
|
||||
color: hsl(218, 22%, 55%); /* #7587A6 */
|
||||
}
|
||||
|
||||
.token.regex,
|
||||
.token.important {
|
||||
color: hsl(42, 75%, 65%); /* #E9C062 */
|
||||
color: hsl(42, 75%, 65%); /* #E9C062 */
|
||||
}
|
||||
|
||||
.token.important,
|
||||
.token.bold {
|
||||
font-weight: bold;
|
||||
font-weight: bold;
|
||||
}
|
||||
.token.italic {
|
||||
font-style: italic;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.token.entity {
|
||||
cursor: help;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
/* Markup */
|
||||
.language-markup .token.tag,
|
||||
.language-markup .token.attr-name,
|
||||
.language-markup .token.punctuation {
|
||||
color: hsl(33, 33%, 52%); /* #AC885B */
|
||||
color: hsl(33, 33%, 52%); /* #AC885B */
|
||||
}
|
||||
|
||||
/* Make the tokens sit above the line highlight so the colours don't look faded. */
|
||||
.token {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.line-highlight.line-highlight {
|
||||
background: hsla(0, 0%, 33%, 0.25); /* #545454 */
|
||||
background: linear-gradient(to right, hsla(0, 0%, 33%, .1) 70%, hsla(0, 0%, 33%, 0)); /* #545454 */
|
||||
border-bottom: 1px dashed hsl(0, 0%, 33%); /* #545454 */
|
||||
border-top: 1px dashed hsl(0, 0%, 33%); /* #545454 */
|
||||
margin-top: 0.75em; /* Same as .prism’s padding-top */
|
||||
z-index: 0;
|
||||
background: hsla(0, 0%, 33%, 0.25); /* #545454 */
|
||||
background: linear-gradient(
|
||||
to right,
|
||||
hsla(0, 0%, 33%, 0.1) 70%,
|
||||
hsla(0, 0%, 33%, 0)
|
||||
); /* #545454 */
|
||||
border-bottom: 1px dashed hsl(0, 0%, 33%); /* #545454 */
|
||||
border-top: 1px dashed hsl(0, 0%, 33%); /* #545454 */
|
||||
margin-top: 0.75em; /* Same as .prism’s padding-top */
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.line-highlight.line-highlight:before,
|
||||
.line-highlight.line-highlight[data-end]:after {
|
||||
background-color: hsl(215, 15%, 59%); /* #8794A6 */
|
||||
color: hsl(24, 20%, 95%); /* #F5F2F0 */
|
||||
background-color: hsl(215, 15%, 59%); /* #8794A6 */
|
||||
color: hsl(24, 20%, 95%); /* #F5F2F0 */
|
||||
}
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||
width="256.000000pt" height="256.000000pt" viewBox="0 0 256.000000 256.000000"
|
||||
preserveAspectRatio="xMidYMid meet">
|
||||
<metadata>
|
||||
<svg
|
||||
version="1.0"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="256.000000pt"
|
||||
height="256.000000pt"
|
||||
viewBox="0 0 256.000000 256.000000"
|
||||
preserveAspectRatio="xMidYMid meet"
|
||||
>
|
||||
<metadata
|
||||
>
|
||||
Created by potrace 1.14, written by Peter Selinger 2001-2017
|
||||
</metadata>
|
||||
<g transform="translate(0.000000,256.000000) scale(0.100000,-0.100000)"
|
||||
fill="#000000" stroke="none">
|
||||
<path d="M1404 2075 c-16 -7 -75 -60 -131 -116 -55 -57 -130 -133 -166 -167
|
||||
<g
|
||||
transform="translate(0.000000,256.000000) scale(0.100000,-0.100000)"
|
||||
fill="#000000"
|
||||
stroke="none"
|
||||
>
|
||||
<path
|
||||
d="M1404 2075 c-16 -7 -75 -60 -131 -116 -55 -57 -130 -133 -166 -167
|
||||
l-64 -64 0 122 c0 91 -3 124 -13 130 -19 12 -192 12 -210 0 -11 -7 -15 -34
|
||||
-16 -117 -1 -59 -3 -110 -3 -113 -1 -3 -20 -11 -43 -17 -67 -18 -126 -76 -164
|
||||
-160 -33 -72 -34 -73 -108 -108 -41 -19 -87 -50 -102 -68 -64 -76 -82 -169
|
||||
@@ -19,6 +29,7 @@ l-64 -64 0 122 c0 91 -3 124 -13 130 -19 12 -192 12 -210 0 -11 -7 -15 -34
|
||||
-59 15 -9 -2 -12 10 -9 45 6 72 -17 145 -62 196 -13 16 -16 60 -16 318 0 164
|
||||
3 299 6 299 3 0 18 -13 34 -30 39 -41 75 -52 113 -33 36 18 53 57 40 93 -5 14
|
||||
-82 96 -171 183 -89 87 -282 277 -429 423 -146 145 -270 264 -275 265 -4 0
|
||||
-15 2 -24 4 -8 1 -29 -3 -45 -10z"/>
|
||||
</g>
|
||||
-15 2 -24 4 -8 1 -29 -3 -45 -10z"
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
@@ -35,7 +35,7 @@ function thumbHashToRGBA(hash) {
|
||||
for (let cx = cy ? 0 : 1; cx * ny < nx * (ny - cy); cx++) {
|
||||
ac.push(
|
||||
(((hash[ac_start + (ac_index >> 1)] >> ((ac_index++ & 1) << 2)) &
|
||||
15) / 7.5 - 1) * scale,
|
||||
15) / 7.5 - 1) * scale,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user