feat: render some real content

This commit is contained in:
Julien Calixte
2026-02-11 03:12:52 +01:00
parent 95b4eb7c44
commit 683187b4d1
10 changed files with 131 additions and 90 deletions

View File

@@ -11,7 +11,7 @@ import {
import StackedNote from "@/components/StackedNote.vue" import StackedNote from "@/components/StackedNote.vue"
import { useLinks } from "@/hooks/useLinks.hook" import { useLinks } from "@/hooks/useLinks.hook"
import { useMarkdown } from "@/hooks/useMarkdown.hook" import { markdownBuilder } from "@/hooks/useMarkdown.hook"
import { useNoteView } from "@/hooks/useNoteView.hook" import { useNoteView } from "@/hooks/useNoteView.hook"
import { useRouteQueryStackedNotes } from "@/hooks/useRouteQueryStackedNotes.hook" import { useRouteQueryStackedNotes } from "@/hooks/useRouteQueryStackedNotes.hook"
import { useVisitRepo } from "@/modules/history/hooks/useVisitRepo.hook" import { useVisitRepo } from "@/modules/history/hooks/useVisitRepo.hook"
@@ -48,7 +48,7 @@ const refProps = toRefs(props)
const store = useUserRepoStore() const store = useUserRepoStore()
useUserSettings() useUserSettings()
const { visitRepo } = useVisitRepo({ user: user, repo: repo }) const { visitRepo } = useVisitRepo({ user: user, repo: repo })
const { toHTML } = useMarkdown(repo) const { toHTML } = markdownBuilder(repo)
const { listenToClick } = useLinks("note-display") const { listenToClick } = useLinks("note-display")
const { stackedNotes, scrollToFocusedNote } = useRouteQueryStackedNotes() const { stackedNotes, scrollToFocusedNote } = useRouteQueryStackedNotes()

View File

@@ -188,34 +188,6 @@ watch(mode, async (newMode) => {
<path d="M16 5l3 3" /> <path d="M16 5l3 3" />
</svg> </svg>
</button> </button>
<router-link
v-if="false"
:to="{
name: 'ShareNotes',
params: { user: user, repo: repo, note: sha },
}"
class="action"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="icon icon-tabler icon-tabler-share"
width="24"
height="24"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<circle cx="6" cy="12" r="3" />
<circle cx="18" cy="6" r="3" />
<circle cx="18" cy="18" r="3" />
<line x1="8.7" y1="10.7" x2="15.3" y2="7.3" />
<line x1="8.7" y1="13.3" x2="15.3" y2="16.7" />
</svg>
</router-link>
<div v-if="mode === 'edit'" class="edit"> <div v-if="mode === 'edit'" class="edit">
<edit-note v-model="rawContent" /> <edit-note v-model="rawContent" />

View File

@@ -1,6 +1,6 @@
import { computed, Ref, ref, toValue } from "vue" import { computed, Ref, ref, toValue } from "vue"
import { useMarkdown } from "@/hooks/useMarkdown.hook" import { markdownBuilder } from "@/hooks/useMarkdown.hook"
import { prepareNoteCache } from "@/modules/note/cache/prepareNoteCache" import { prepareNoteCache } from "@/modules/note/cache/prepareNoteCache"
import { queryFileContent } from "@/modules/repo/services/repo" import { queryFileContent } from "@/modules/repo/services/repo"
import { useUserRepoStore } from "@/modules/repo/store/userRepo.store" import { useUserRepoStore } from "@/modules/repo/store/userRepo.store"
@@ -18,7 +18,7 @@ export const useFile = (sha: Ref<string> | string, retrieveContent = true) => {
render, render,
renderFromUTF8, renderFromUTF8,
getRawContent: getRawContentFromFile, getRawContent: getRawContentFromFile,
} = useMarkdown(shaValue) } = markdownBuilder(shaValue)
const { getCachedNote, saveCacheNote } = prepareNoteCache( const { getCachedNote, saveCacheNote } = prepareNoteCache(
shaValue, shaValue,

View File

@@ -116,7 +116,7 @@ const rules: Renderer.RenderRuleRecord = {
md.renderer.rules = { ...md.renderer.rules, ...rules } md.renderer.rules = { ...md.renderer.rules, ...rules }
export const useMarkdown = (defaultPrefix?: Ref<string> | string) => { export const markdownBuilder = (defaultPrefix?: Ref<string> | string) => {
const getRawContent = (content: string) => decodeBase64ToUTF8(content) const getRawContent = (content: string) => decodeBase64ToUTF8(content)
const renderFromUTF8 = (content: string, prefix?: string) => const renderFromUTF8 = (content: string, prefix?: string) =>
content content

View File

@@ -1,5 +1,22 @@
const correspondanceCache = new Map<string, string>() const correspondanceCache = new Map<string, string>()
export const getUniqueAka = async (did: string) => {
if (correspondanceCache.has(did)) {
return correspondanceCache.get(did) as string
}
const response = await fetch(`https://plc.directory/${did}`)
const {
alsoKnownAs: [aka],
} = await response.json()
const alias = aka.replace("at://", "")
correspondanceCache.set(did, alias)
return alias
}
export const getAka = async (dids: Set<string>) => { export const getAka = async (dids: Set<string>) => {
const correspondance = await Promise.all( const correspondance = await Promise.all(
[...dids].map(async (did) => { [...dids].map(async (did) => {

View File

@@ -1,10 +1,24 @@
export const getUrl = async ({ did, rkey }: { did: string; rkey: string }) => { const endpointCache = new Map<string, string>()
const getEndpoint = async (did: string) => {
if (endpointCache.has(did)) {
return endpointCache.get(did)
}
const response = await fetch(`https://plc.directory/${did}`) const response = await fetch(`https://plc.directory/${did}`)
const { const {
service: [{ serviceEndpoint }], service: [{ serviceEndpoint }],
} = await response.json() } = await response.json()
const url = new URL("/xrpc/com.atproto.repo.getRecord", serviceEndpoint) endpointCache.set(did, serviceEndpoint)
return serviceEndpoint as string
}
export const getUrl = async ({ did, rkey }: { did: string; rkey: string }) => {
const url = new URL(
"/xrpc/com.atproto.repo.getRecord",
await getEndpoint(did),
)
url.searchParams.set("repo", did) url.searchParams.set("repo", did)
url.searchParams.set("collection", "space.litenote.note") url.searchParams.set("collection", "space.litenote.note")
url.searchParams.set("rkey", rkey) url.searchParams.set("rkey", rkey)

View File

@@ -1,18 +1,18 @@
// https://npm.io/package/supermemo // https://npm.io/package/supermemo
import { useAsyncState } from '@vueuse/core' import { useAsyncState } from "@vueuse/core"
import { addDays, isAfter } from 'date-fns' import { addDays, isAfter } from "date-fns"
import { computed, nextTick, watch } from 'vue' import { computed, nextTick, watch } from "vue"
import { data } from '@/data/data' import { data } from "@/data/data"
import { DataType } from '@/data/DataType.enum' import { DataType } from "@/data/DataType.enum"
import { useFile } from '@/hooks/useFile.hook' import { useFile } from "@/hooks/useFile.hook"
import { useLinks } from '@/hooks/useLinks.hook' import { useLinks } from "@/hooks/useLinks.hook"
import { useMarkdown } from '@/hooks/useMarkdown.hook' import { markdownBuilder } from "@/hooks/useMarkdown.hook"
import { Card } from '@/modules/card/models/Card' import { Card } from "@/modules/card/models/Card"
import { RepetitionCard } from '@/modules/card/models/RepetitionCard' import { RepetitionCard } from "@/modules/card/models/RepetitionCard"
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store' import { useUserRepoStore } from "@/modules/repo/store/userRepo.store"
import { decodeBase64ToUTF8 } from '@/utils/decodeBase64ToUTF8' import { decodeBase64ToUTF8 } from "@/utils/decodeBase64ToUTF8"
const MAX_LEVEL = 8 const MAX_LEVEL = 8
@@ -22,23 +22,23 @@ export interface Repetition {
} }
export const useSpacedRepetitionCards = () => { export const useSpacedRepetitionCards = () => {
const { toHTML } = useMarkdown() const { toHTML } = markdownBuilder()
const store = useUserRepoStore() const store = useUserRepoStore()
const { listenToClick } = useLinks('flip-card') const { listenToClick } = useLinks("flip-card")
const cardFiles = computed(() => const cardFiles = computed(() =>
store.files.filter( store.files.filter(
(file) => (file) =>
file.path !== undefined && file.path !== undefined &&
file.path.startsWith('_cards') && file.path.startsWith("_cards") &&
file.path.endsWith('.md') file.path.endsWith(".md"),
) ),
) )
const { const {
state: cards, state: cards,
isReady, isReady,
execute execute,
} = useAsyncState( } = useAsyncState(
async () => { async () => {
const cards: Repetition[] = [] const cards: Repetition[] = []
@@ -55,7 +55,7 @@ export const useSpacedRepetitionCards = () => {
$type: DataType.RepetitionCard, $type: DataType.RepetitionCard,
level: 1, level: 1,
repeatDate: new Date(), repeatDate: new Date(),
needsReview: false needsReview: false,
}) })
if ( if (
@@ -67,30 +67,30 @@ export const useSpacedRepetitionCards = () => {
} }
const { getContent } = useFile(cardFile.sha, false) const { getContent } = useFile(cardFile.sha, false)
const content = (await getContent()) ?? '' const content = (await getContent()) ?? ""
const [front, back, references] = const [front, back, references] =
decodeBase64ToUTF8(content).split('___') ?? [] decodeBase64ToUTF8(content).split("___") ?? []
cards.push({ cards.push({
repetition, repetition,
card: { card: {
front: toHTML(front), front: toHTML(front),
back: toHTML(back), back: toHTML(back),
references: toHTML(references) references: toHTML(references),
} },
}) })
} }
return cards return cards
}, },
[], [],
{ immediate: false } { immediate: false },
) )
const successRepetition = async (cardId: string) => { const successRepetition = async (cardId: string) => {
const repetition = await data.get<DataType.RepetitionCard, RepetitionCard>( const repetition = await data.get<DataType.RepetitionCard, RepetitionCard>(
cardId cardId,
) )
if (!repetition) { if (!repetition) {
return return
@@ -100,13 +100,13 @@ export const useSpacedRepetitionCards = () => {
...repetition, ...repetition,
needsReview: false, needsReview: false,
level: Math.min(repetition.level + 1, MAX_LEVEL), level: Math.min(repetition.level + 1, MAX_LEVEL),
repeatDate: addDays(new Date(), 2 ** repetition.level) repeatDate: addDays(new Date(), 2 ** repetition.level),
}) })
} }
const failRepetition = async (cardId: string) => { const failRepetition = async (cardId: string) => {
const repetition = await data.get<DataType.RepetitionCard, RepetitionCard>( const repetition = await data.get<DataType.RepetitionCard, RepetitionCard>(
cardId cardId,
) )
if (!repetition) { if (!repetition) {
return return
@@ -118,13 +118,13 @@ export const useSpacedRepetitionCards = () => {
...repetition, ...repetition,
level, level,
needsReview: false, needsReview: false,
repeatDate: addDays(new Date(), level) repeatDate: addDays(new Date(), level),
}) })
} }
const needsReview = async (cardId: string) => { const needsReview = async (cardId: string) => {
const repetition = await data.get<DataType.RepetitionCard, RepetitionCard>( const repetition = await data.get<DataType.RepetitionCard, RepetitionCard>(
cardId cardId,
) )
if (!repetition) { if (!repetition) {
return return
@@ -132,7 +132,7 @@ export const useSpacedRepetitionCards = () => {
await data.update<DataType.RepetitionCard, RepetitionCard>({ await data.update<DataType.RepetitionCard, RepetitionCard>({
...repetition, ...repetition,
needsReview: true needsReview: true,
}) })
} }
@@ -142,7 +142,7 @@ export const useSpacedRepetitionCards = () => {
nextTick(() => { nextTick(() => {
listenToClick() listenToClick()
}), }),
{ immediate: true } { immediate: true },
) )
watch(cardFiles, () => execute()) watch(cardFiles, () => execute())
@@ -152,6 +152,6 @@ export const useSpacedRepetitionCards = () => {
successRepetition, successRepetition,
failRepetition, failRepetition,
needsReview, needsReview,
isLoading: !isReady isLoading: !isReady,
} }
} }

View File

@@ -1,4 +1,4 @@
import { useMarkdown } from "@/hooks/useMarkdown.hook" import { markdownBuilder } from "@/hooks/useMarkdown.hook"
import { prepareNoteCache } from "@/modules/note/cache/prepareNoteCache" import { prepareNoteCache } from "@/modules/note/cache/prepareNoteCache"
import { RepoFile } from "@/modules/repo/interfaces/RepoFile" import { RepoFile } from "@/modules/repo/interfaces/RepoFile"
import { UserSettings } from "@/modules/repo/interfaces/UserSettings" import { UserSettings } from "@/modules/repo/interfaces/UserSettings"
@@ -41,7 +41,7 @@ export const getCachedMainReadme = async (owner: string, repo: string) => {
if (!owner || !repo) { if (!owner || !repo) {
return null return null
} }
const { render } = useMarkdown() const { render } = markdownBuilder()
const { getCachedNote } = prepareNoteCache(`${owner}-${repo}-README`) const { getCachedNote } = prepareNoteCache(`${owner}-${repo}-README`)
const { note: cachedReadme } = await getCachedNote() const { note: cachedReadme } = await getCachedNote()
@@ -58,7 +58,7 @@ export const getMainReadme = async (owner: string, repo: string) => {
return null return null
} }
const { render } = useMarkdown() const { render } = markdownBuilder()
const { getCachedNote, saveCacheNote } = prepareNoteCache( const { getCachedNote, saveCacheNote } = prepareNoteCache(
`${owner}-${repo}-README`, `${owner}-${repo}-README`,
) )

View File

@@ -1,24 +1,66 @@
<script setup lang="ts"> <script setup lang="ts">
import { markdownBuilder } from "@/hooks/useMarkdown.hook"
import { getUniqueAka } from "@/modules/atproto/getAka"
import { getUrl } from "@/modules/atproto/getUrl" import { getUrl } from "@/modules/atproto/getUrl"
import { computedAsync } from "@vueuse/core" import { computedAsync } from "@vueuse/core"
import { computed } from "vue" import { computed } from "vue"
export interface Root {
uri: string
cid: string
value: Value
}
export interface Value {
$type: string
title: string
images: Image[]
content: string
createdAt: string
publishedAt: string
}
export interface Image {
alt: string
image: Image2
}
export interface Image2 {
$type: string
ref: Ref
mimeType: string
size: number
}
export interface Ref {
$link: string
}
const props = defineProps<{ did: string; rkey: string }>() const props = defineProps<{ did: string; rkey: string }>()
const did = computed(() => props.did) const did = computed(() => props.did)
const rkey = computed(() => props.rkey) const rkey = computed(() => props.rkey)
const alias = computedAsync(async () => getUniqueAka(did.value))
const url = computedAsync(async () => const url = computedAsync(async () =>
getUrl({ did: did.value, rkey: rkey.value }), getUrl({ did: did.value, rkey: rkey.value }),
) )
const content = computedAsync(async () => const rawContent = computedAsync(async () =>
url.value ? (await fetch(url.value).then()).json() : null, url.value ? ((await fetch(url.value).then()).json() as Promise<Root>) : null,
)
const { toHTML } = markdownBuilder()
// const title = computed(() => rawContent.value?.value.title)
const content = computed(() =>
rawContent.value?.value.content
? toHTML(rawContent.value?.value.content)
: "",
) )
</script> </script>
<template> <template>
<div class="public-note-view"> <div class="public-note-view">
{{ did }}/{{ rkey }}@{{ url }} <span v-if="alias">{{ alias }}</span>
<pre>{{ content }}</pre> <div v-html="content"></div>
</div> </div>
</template> </template>

View File

@@ -2,7 +2,7 @@
import { computed, defineAsyncComponent, nextTick, ref, watch } from "vue" import { computed, defineAsyncComponent, nextTick, ref, watch } from "vue"
import { useUserRepoStore } from "@/modules/repo/store/userRepo.store" import { useUserRepoStore } from "@/modules/repo/store/userRepo.store"
import { useCheckboxCommit } from "@/hooks/useCheckboxCommit.hook" import { useCheckboxCommit } from "@/hooks/useCheckboxCommit.hook"
import { useMarkdown } from "@/hooks/useMarkdown.hook" import { markdownBuilder } from "@/hooks/useMarkdown.hook"
import { queryFileContent } from "@/modules/repo/services/repo" import { queryFileContent } from "@/modules/repo/services/repo"
import { decodeBase64ToUTF8 } from "@/utils/decodeBase64ToUTF8" import { decodeBase64ToUTF8 } from "@/utils/decodeBase64ToUTF8"
@@ -20,15 +20,11 @@ const todoNote = computed(() =>
const sha = computed(() => todoNote.value?.sha ?? "") const sha = computed(() => todoNote.value?.sha ?? "")
const path = computed(() => todoNote.value?.path) const path = computed(() => todoNote.value?.path)
const { toHTML } = useMarkdown(repo) const { toHTML } = markdownBuilder(repo)
// Setup checkbox commit handler // Setup checkbox commit handler
const { const { pendingContent, syncContent, listenToCheckboxes, hasPendingChanges } =
pendingContent, useCheckboxCommit({
syncContent,
listenToCheckboxes,
hasPendingChanges,
} = useCheckboxCommit({
user: props.user, user: props.user,
repo: props.repo, repo: props.repo,
path, path,