From 112538d90a8f9c0cd31a7c36daa833caf32968b6 Mon Sep 17 00:00:00 2001 From: Jeremy Butler Date: Thu, 18 Jan 2024 15:54:51 +1000 Subject: [PATCH] Add navigation and sidebar --- .gitignore | 1 - docs.ts | 11 +++++++++-- .../docs/components/CopyToClipboard.vue | 15 +++++++++++++-- nuxt-module/docs/components/Example.vue | 2 +- .../content/1.information/1.introduction.md | 4 ++++ .../content/1.information/installation.md | 4 ++++ .../docs/content/1.information/next.md | 4 ++++ .../docs/content/1.information/nuxt.md | 4 ++++ .../formatters.md => 2.docs/1.formatters.md} | 7 +++++++ .../content/{1.docs => 2.docs}/actions.md | 6 ++++++ .../content/{1.docs => 2.docs}/detections.md | 6 ++++++ .../content/{1.docs => 2.docs}/generators.md | 6 ++++++ .../content/{1.docs => 2.docs}/modifiers.md | 6 ++++++ .../content/{1.docs => 2.docs}/numbers.md | 10 ++++++++++ .../content/{1.docs => 2.docs}/validators.md | 6 ++++++ nuxt-module/docs/layouts/default.vue | 19 ++++++++++++++++--- src/actions.ts | 16 +++++++--------- src/formatters.ts | 2 +- src/numbers.ts | 2 +- 19 files changed, 111 insertions(+), 20 deletions(-) create mode 100644 nuxt-module/docs/content/1.information/1.introduction.md create mode 100644 nuxt-module/docs/content/1.information/installation.md create mode 100644 nuxt-module/docs/content/1.information/next.md create mode 100644 nuxt-module/docs/content/1.information/nuxt.md rename nuxt-module/docs/content/{1.docs/formatters.md => 2.docs/1.formatters.md} (88%) rename nuxt-module/docs/content/{1.docs => 2.docs}/actions.md (96%) rename nuxt-module/docs/content/{1.docs => 2.docs}/detections.md (98%) rename nuxt-module/docs/content/{1.docs => 2.docs}/generators.md (80%) rename nuxt-module/docs/content/{1.docs => 2.docs}/modifiers.md (90%) rename nuxt-module/docs/content/{1.docs => 2.docs}/numbers.md (94%) rename nuxt-module/docs/content/{1.docs => 2.docs}/validators.md (98%) diff --git a/.gitignore b/.gitignore index 52e191e4..33fc73c4 100755 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,3 @@ sw.* .output docs/content/2.functions nuxt-module/docs/content/1.docs -nuxt-module/docs/content/1.docs diff --git a/docs.ts b/docs.ts index 795cb828..f6e3db6a 100644 --- a/docs.ts +++ b/docs.ts @@ -3,14 +3,14 @@ import { resolve, extname, basename, join } from 'path' // Define the directory path const directoryPath = resolve('./src/') -const contentDirectory = resolve('./nuxt-module/docs/content/1.docs') +const contentDirectory = resolve('./nuxt-module/docs/content/2.docs') const functionPattern = /\/\*\*[\s\S]*?\*\/\s*(export\s+function\s+[a-zA-Z0-9_]+\([^)]*\)\s*:\s*[a-zA-Z]+\s*(?:{[\s\S]*?})?)?/gms const metadataPattern = /\/\/\s+(title|description):\s+([^\r\n]*)/g async function processFiles() { try { - const tsFiles = (await readdir(directoryPath)).filter((file) => extname(file) === '.ts') + const tsFiles = (await readdir(directoryPath)).filter((file) => extname(file) === '.ts' && file !== 'index.ts') let combinedTsFile = '' @@ -31,6 +31,13 @@ function generateMarkdown(tsContent: string): string { let markdownContent = '' + // Create Frontmatter + markdownContent += `---\n` + markdownContent += `title: ${metadata.title}\n` + markdownContent += `description: ${metadata.description}\n` + markdownContent += `icon: ${metadata.icon}\n` + markdownContent += `---\n\n` + if (metadata.title) markdownContent += `::pagetitle\n` if (metadata.title) markdownContent += `# ${metadata.title}\n` if (metadata.description) markdownContent += `${metadata.description}\n` diff --git a/nuxt-module/docs/components/CopyToClipboard.vue b/nuxt-module/docs/components/CopyToClipboard.vue index 4c143223..7c046c98 100644 --- a/nuxt-module/docs/components/CopyToClipboard.vue +++ b/nuxt-module/docs/components/CopyToClipboard.vue @@ -1,6 +1,7 @@ @@ -11,4 +12,14 @@ default: '' } }) + + const copied = ref(false) + + function copy(text: string) { + copyToClipboard(text) + copied.value = true + setTimeout(() => { + copied.value = false + }, 1000) + } diff --git a/nuxt-module/docs/components/Example.vue b/nuxt-module/docs/components/Example.vue index 271effb9..6f4a1bfb 100644 --- a/nuxt-module/docs/components/Example.vue +++ b/nuxt-module/docs/components/Example.vue @@ -1,5 +1,5 @@ diff --git a/nuxt-module/docs/content/1.information/1.introduction.md b/nuxt-module/docs/content/1.information/1.introduction.md new file mode 100644 index 00000000..46976302 --- /dev/null +++ b/nuxt-module/docs/content/1.information/1.introduction.md @@ -0,0 +1,4 @@ +--- +title: Introduction +description: Actions are similar to mutations, the differences being that +--- \ No newline at end of file diff --git a/nuxt-module/docs/content/1.information/installation.md b/nuxt-module/docs/content/1.information/installation.md new file mode 100644 index 00000000..c7b6e7b4 --- /dev/null +++ b/nuxt-module/docs/content/1.information/installation.md @@ -0,0 +1,4 @@ +--- +title: Installation +description: Actions are similar to mutations, the differences being that +--- \ No newline at end of file diff --git a/nuxt-module/docs/content/1.information/next.md b/nuxt-module/docs/content/1.information/next.md new file mode 100644 index 00000000..dc691aeb --- /dev/null +++ b/nuxt-module/docs/content/1.information/next.md @@ -0,0 +1,4 @@ +--- +title: Next +description: Actions are similar to mutations, the differences being that +--- \ No newline at end of file diff --git a/nuxt-module/docs/content/1.information/nuxt.md b/nuxt-module/docs/content/1.information/nuxt.md new file mode 100644 index 00000000..d8cec5c4 --- /dev/null +++ b/nuxt-module/docs/content/1.information/nuxt.md @@ -0,0 +1,4 @@ +--- +title: Nuxt +description: Actions are similar to mutations, the differences being that +--- \ No newline at end of file diff --git a/nuxt-module/docs/content/1.docs/formatters.md b/nuxt-module/docs/content/2.docs/1.formatters.md similarity index 88% rename from nuxt-module/docs/content/1.docs/formatters.md rename to nuxt-module/docs/content/2.docs/1.formatters.md index abeb62e4..c3312da4 100644 --- a/nuxt-module/docs/content/1.docs/formatters.md +++ b/nuxt-module/docs/content/2.docs/1.formatters.md @@ -1,3 +1,9 @@ +--- +title: Formatters +description: A collection of formatters for common data types +icon: undefined +--- + ::pagetitle # Formatters A collection of formatters for common data types @@ -23,6 +29,7 @@ formatValuation(1234567890) ::: :: +Format numbers into thousands, millions or billions ::pagefunction ### formatDuration Format time into hours, minutes, and seconds diff --git a/nuxt-module/docs/content/1.docs/actions.md b/nuxt-module/docs/content/2.docs/actions.md similarity index 96% rename from nuxt-module/docs/content/1.docs/actions.md rename to nuxt-module/docs/content/2.docs/actions.md index 03a8900c..734940a6 100644 --- a/nuxt-module/docs/content/1.docs/actions.md +++ b/nuxt-module/docs/content/2.docs/actions.md @@ -1,3 +1,9 @@ +--- +title: Actions +description: A collection of useful actions +icon: undefined +--- + ::pagetitle # Actions A collection of useful actions diff --git a/nuxt-module/docs/content/1.docs/detections.md b/nuxt-module/docs/content/2.docs/detections.md similarity index 98% rename from nuxt-module/docs/content/1.docs/detections.md rename to nuxt-module/docs/content/2.docs/detections.md index d4c369a0..17a51140 100644 --- a/nuxt-module/docs/content/1.docs/detections.md +++ b/nuxt-module/docs/content/2.docs/detections.md @@ -1,3 +1,9 @@ +--- +title: Detections +description: A collection of detections for common data types +icon: undefined +--- + ::pagetitle # Detections A collection of detections for common data types diff --git a/nuxt-module/docs/content/1.docs/generators.md b/nuxt-module/docs/content/2.docs/generators.md similarity index 80% rename from nuxt-module/docs/content/1.docs/generators.md rename to nuxt-module/docs/content/2.docs/generators.md index 63fe0736..ecb06b75 100644 --- a/nuxt-module/docs/content/1.docs/generators.md +++ b/nuxt-module/docs/content/2.docs/generators.md @@ -1,3 +1,9 @@ +--- +title: Generators +description: A collection of generators +icon: undefined +--- + ::pagetitle # Generators A collection of generators diff --git a/nuxt-module/docs/content/1.docs/modifiers.md b/nuxt-module/docs/content/2.docs/modifiers.md similarity index 90% rename from nuxt-module/docs/content/1.docs/modifiers.md rename to nuxt-module/docs/content/2.docs/modifiers.md index 7527295a..de6c3bf7 100644 --- a/nuxt-module/docs/content/1.docs/modifiers.md +++ b/nuxt-module/docs/content/2.docs/modifiers.md @@ -1,3 +1,9 @@ +--- +title: Modifiers +description: Modifiers are a key feature of Mods that allow you to easily modify and enhance your content. They are small pieces of code that can be applied to your JS to add functionality, validation or style. +icon: undefined +--- + ::pagetitle # Modifiers Modifiers are a key feature of Mods that allow you to easily modify and enhance your content. They are small pieces of code that can be applied to your JS to add functionality, validation or style. diff --git a/nuxt-module/docs/content/1.docs/numbers.md b/nuxt-module/docs/content/2.docs/numbers.md similarity index 94% rename from nuxt-module/docs/content/1.docs/numbers.md rename to nuxt-module/docs/content/2.docs/numbers.md index c9907398..590e54bd 100644 --- a/nuxt-module/docs/content/1.docs/numbers.md +++ b/nuxt-module/docs/content/2.docs/numbers.md @@ -1,4 +1,14 @@ +--- +title: Numbers +description: This file contains functions that are related to numbers. +icon: undefined +--- + +::pagetitle +# Numbers This file contains functions that are related to numbers. +:: + ::pagefunction ### random Generates a random integer between the specified minimum and maximum values. diff --git a/nuxt-module/docs/content/1.docs/validators.md b/nuxt-module/docs/content/2.docs/validators.md similarity index 98% rename from nuxt-module/docs/content/1.docs/validators.md rename to nuxt-module/docs/content/2.docs/validators.md index 2207f094..520c5148 100644 --- a/nuxt-module/docs/content/1.docs/validators.md +++ b/nuxt-module/docs/content/2.docs/validators.md @@ -1,3 +1,9 @@ +--- +title: Validators +description: A collection of validators for common data types +icon: undefined +--- + ::pagetitle # Validators A collection of validators for common data types diff --git a/nuxt-module/docs/layouts/default.vue b/nuxt-module/docs/layouts/default.vue index f73c07a1..1a45c181 100644 --- a/nuxt-module/docs/layouts/default.vue +++ b/nuxt-module/docs/layouts/default.vue @@ -5,9 +5,12 @@
- -
+ + + + diff --git a/src/actions.ts b/src/actions.ts index f3803c4c..6ba4dce7 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -1,5 +1,6 @@ // title: Actions // description: A collection of useful actions +// icon: lightning-bolt /** * Scrolls to the element with the specified ID. @@ -73,15 +74,12 @@ export function toggleElementScroll(element: HTMLElement, className: string) { * Copies a text to the clipboard * @example copyToClipboard() */ -export function copyToClipboard(text: string | number, callback?: () => void) { - navigator.clipboard - .writeText(String(text)) - .then(() => { - if (callback) callback() - }) - .catch((error) => { - if (callback) callback() - }) +export async function copyToClipboard(text: string): Promise { + try { + await navigator.clipboard.writeText(String(text)) + } catch (error) { + console.error(error) + } } /** diff --git a/src/formatters.ts b/src/formatters.ts index 77ea9c63..a3877252 100644 --- a/src/formatters.ts +++ b/src/formatters.ts @@ -8,7 +8,7 @@ export function formatCurrency(number: number, decimals = 2, currency = 'USD'): string { const formatter = new Intl.NumberFormat('en-US', { style: 'currency', - minimumFractionDigits: 0, + minimumFractionDigits: decimals, maximumFractionDigits: decimals, currency }) diff --git a/src/numbers.ts b/src/numbers.ts index 111e674c..a86fcabf 100644 --- a/src/numbers.ts +++ b/src/numbers.ts @@ -1,4 +1,4 @@ -// titile: Numbers +// title: Numbers // description: This file contains functions that are related to numbers. /**