-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Documentation page improvements (#50)
- Loading branch information
1 parent
54d2014
commit 0ffdb6c
Showing
6 changed files
with
88 additions
and
21 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,24 +1,65 @@ | ||
<script setup lang="ts"> | ||
const { data: blogPost } = await useAsyncData('blogToc', () => | ||
import scrollIntoView from 'scroll-into-view-if-needed' | ||
const { data: documentation } = await useAsyncData('blogToc', () => | ||
queryContent('/documentation').findOne() | ||
) | ||
const tocLinks = computed(() => blogPost.value?.body.toc.links ?? []) | ||
const currentlyActiveId = ref(null as string | null) | ||
const content = ref<HTMLDivElement>() | ||
const tocLinks = computed(() => documentation.value?.body.toc.links ?? []) | ||
const scrollToId = function (id: string) { | ||
const navigationElement = document.querySelector(`nav [href="#${id}"]`) | ||
if (navigationElement) { | ||
scrollIntoView(navigationElement, { | ||
scrollMode: 'if-needed', | ||
behavior: 'smooth', | ||
block: 'center', | ||
inline: 'start' | ||
}) | ||
} | ||
} | ||
const trackCurrentlyActiveId = function () { | ||
const observer = new IntersectionObserver((entries) => { | ||
entries.forEach((entry) => { | ||
if (entry.isIntersecting) { | ||
const id = entry.target.getAttribute('id') | ||
if (id) { | ||
currentlyActiveId.value = id | ||
scrollToId(id) | ||
} | ||
} | ||
}) | ||
}, { | ||
root: document, | ||
rootMargin: '0px 0px -90%', | ||
threshold: 0 | ||
}) | ||
document | ||
.querySelectorAll('.markdown-body h2[id], .markdown-body h3[id]') | ||
.forEach((section) => { | ||
observer.observe(section) | ||
}) | ||
} | ||
onMounted(trackCurrentlyActiveId) | ||
useHead({ | ||
title: 'Makerdao Document Model Documentation' | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="w-full max-w-screen-2xl m-auto"> | ||
<ContentDoc path="/documentation" class="w-full"> | ||
<template #default="{doc}"> | ||
<div class="flex flex-row w-full px-4"> | ||
<div class="flex-shrink-0 w-56 py-3 hidden md:block h-screen overflow-x-scroll sticky top-14"> | ||
<DocTableOfContents :toc-links="tocLinks" class="pb-14" /> | ||
</div> | ||
<div class="flex-grow w-[calc(100%-28rem)] p-4 pt-2 mt-4 bg-white w-full"> | ||
<ContentRenderer :value="doc" class="markdown-body w-full" /> | ||
</div> | ||
</div> | ||
</template> | ||
</ContentDoc> | ||
<div ref="content" class="w-full max-w-screen-2xl m-auto"> | ||
<div class="flex flex-row w-full px-4"> | ||
<div class="flex-shrink-0 w-56 py-3 hidden md:block h-screen overflow-x-scroll sticky top-14"> | ||
<DocTableOfContents :toc-links="tocLinks" :currently-active-id="currentlyActiveId" class="pb-14" /> | ||
</div> | ||
<div class="flex-grow !w-[calc(100%-18rem)] p-4 pt-2 mt-4 bg-white w-full"> | ||
<ContentRendererMarkdown v-if="documentation" :value="documentation" class="markdown-body w-full" /> | ||
</div> | ||
</div> | ||
</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