-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
94 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<script setup lang="ts"> | ||
import { onBeforeMount, ref, watch } from 'vue3' | ||
import { fetchPreviewOrigin, previewUrl, previewPath } from '../composables/preview' | ||
const iframe = ref<HTMLIFrameElement>() | ||
onBeforeMount(() => fetchPreviewOrigin()) | ||
watch( | ||
[previewUrl, iframe], | ||
() => { | ||
if (!iframe.value) return | ||
try { | ||
iframe.value.contentWindow.$nuxt.$router.push(previewPath.value) | ||
} catch (e) { | ||
// fallback to hard refresh when working with cross-origin | ||
iframe.value.src = previewUrl.value | ||
} | ||
}, | ||
{ flush: 'post' } | ||
) | ||
function refresh() { | ||
iframe.value.src += '' | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="h-full flex-1 grid grid-rows-[min-content,1fr]"> | ||
<div class="p-2 flex d-border-primary border-b"> | ||
<div class="flex-auto my-auto px-2">{{ previewUrl }}</div> | ||
<button class="border d-border-primary rounded px-2 py-1" @click="refresh">Refresh</button> | ||
</div> | ||
<iframe ref="iframe" :src="previewOrigin" class="w-full h-full" /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './preview' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ref, computed } from 'vue3' | ||
import { useApi } from '../plugins/api' | ||
|
||
export const previewOrigin = ref('http://localhost:4000') | ||
export const previewPath = ref('/') | ||
export const previewUrl = computed(() => previewOrigin.value + previewPath.value) | ||
|
||
const api = useApi() | ||
|
||
export async function fetchPreviewOrigin() { | ||
const { url } = (await api.get('/preview')) as any | ||
|
||
previewOrigin.value = url | ||
} | ||
|
||
export function navigateToFile(filepath: string) { | ||
previewPath.value = filepath | ||
.replace(/\/\d+\./g, '/') | ||
.replace(/\.md$/, '') | ||
.replace(/\/index$/, '/') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters