You've already forked obsidian-visualiser
Markdown editor in progress + Login and session process completed
This commit is contained in:
@@ -1,24 +1,23 @@
|
||||
import { createMarkdownParser } from "@nuxtjs/mdc/runtime/parser/index";
|
||||
import RemarkBreaks from "remark-breaks";
|
||||
import RemarkOfm from "remark-ofm";
|
||||
import { unified, type Processor } from "unified";
|
||||
import type { Root } from 'hast';
|
||||
import RemarkParse from "remark-parse";
|
||||
|
||||
export default function useMarkdown(): Awaited<ReturnType<typeof createMarkdownParser>>
|
||||
import RemarkRehype from 'remark-rehype';
|
||||
import RemarkOfm from 'remark-ofm';
|
||||
import RemarkGfm from 'remark-gfm';
|
||||
|
||||
export default function useMarkdown(): (md: string) => Root
|
||||
{
|
||||
let parser: Awaited<ReturnType<typeof createMarkdownParser>>
|
||||
let processor: Processor;
|
||||
|
||||
const parse = async (markdown: string) => {
|
||||
if (!parser)
|
||||
const parse = (markdown: string) => {
|
||||
if (!processor)
|
||||
{
|
||||
parser = await createMarkdownParser({
|
||||
remark: {
|
||||
plugins: {
|
||||
'remark-breaks': { instance: RemarkBreaks },
|
||||
'remark-ofm': { instance: RemarkOfm }
|
||||
}
|
||||
},
|
||||
});
|
||||
processor = unified().use([RemarkParse, RemarkGfm, RemarkOfm, RemarkRehype]);
|
||||
}
|
||||
return parser(markdown);
|
||||
|
||||
const processed = processor.runSync(processor.parse(markdown)) as Root;
|
||||
return processed;
|
||||
}
|
||||
|
||||
return parse;
|
||||
|
||||
40
composables/useUserSession.ts
Normal file
40
composables/useUserSession.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import type { UserSession, UserSessionComposable } from '~/types/auth'
|
||||
|
||||
const useSessionState = () => useState<UserSession>('nuxt-session', () => ({}))
|
||||
const useAuthReadyState = () => useState('nuxt-auth-ready', () => false)
|
||||
|
||||
/**
|
||||
* Composable to get back the user session and utils around it.
|
||||
* @see https://github.com/atinux/nuxt-auth-utils
|
||||
*/
|
||||
export function useUserSession(): UserSessionComposable {
|
||||
const sessionState = useSessionState()
|
||||
const authReadyState = useAuthReadyState()
|
||||
return {
|
||||
ready: computed(() => authReadyState.value),
|
||||
loggedIn: computed(() => Boolean(sessionState.value.user)),
|
||||
user: computed(() => sessionState.value.user || null),
|
||||
session: sessionState,
|
||||
fetch,
|
||||
clear,
|
||||
}
|
||||
}
|
||||
|
||||
async function fetch() {
|
||||
const authReadyState = useAuthReadyState()
|
||||
useSessionState().value = await useRequestFetch()('/api/auth/session', {
|
||||
headers: {
|
||||
Accept: 'text/json',
|
||||
},
|
||||
retry: false,
|
||||
}).catch(() => ({}))
|
||||
if (!authReadyState.value) {
|
||||
authReadyState.value = true
|
||||
}
|
||||
}
|
||||
|
||||
async function clear() {
|
||||
await $fetch('/api/auth/session', { method: 'DELETE' })
|
||||
useSessionState().value = {}
|
||||
useRouter().go(0);
|
||||
}
|
||||
Reference in New Issue
Block a user