From f3d345d0f55fb3dd616e0ccfa387ca8e8fe55999 Mon Sep 17 00:00:00 2001 From: dmick92 Date: Thu, 18 Jan 2024 19:02:34 -0500 Subject: [PATCH] Created recursive document listing component + created app index pages --- components/docList/index.tsx | 74 +++++++++++++++++++++++++---- pages/catalyst/index.mdx | 14 +++--- pages/commerce/_meta.json | 7 ++- pages/commerce/index.mdx | 13 +++++ pages/creator/_meta.json | 5 ++ pages/creator/index.mdx | 15 ++++++ pages/crm/index.mdx | 6 ++- pages/deluge/index.mdx | 13 +++++ pages/deluge/timeDates/_meta.json | 3 -- pages/desk/_meta.json | 6 +++ pages/desk/index.mdx | 13 +++++ pages/desk/searchWithCustomField.md | 9 +++- pages/index.mdx | 44 +++-------------- pages/sites/_meta.json | 11 +++-- pages/sites/index.mdx | 15 ++++++ 15 files changed, 184 insertions(+), 64 deletions(-) create mode 100644 pages/commerce/index.mdx create mode 100644 pages/creator/_meta.json create mode 100644 pages/creator/index.mdx create mode 100644 pages/deluge/index.mdx delete mode 100644 pages/deluge/timeDates/_meta.json create mode 100644 pages/desk/_meta.json create mode 100644 pages/desk/index.mdx create mode 100644 pages/sites/index.mdx diff --git a/components/docList/index.tsx b/components/docList/index.tsx index 7eb9a1e..e6967ee 100644 --- a/components/docList/index.tsx +++ b/components/docList/index.tsx @@ -1,12 +1,54 @@ import { Cards, Card } from "nextra/components"; import { useEffect, useState } from "react"; -export const RawDocuments = async (folder) => { - return await fetch(`https://api.github.com/repos/nickmackenzie/dont-get-zohod/contents/pages/${folder}`) - .then(response => response.json()) - .catch(error => { - console.error('Error fetching file list:', error); - }); +type GithubFile = { + name: string, + path: string, + sha: string, + size: number, + url: string, + html_url: string, + git_url: string, + download_url: string, + type: string, + _links: { + self: string, + git: string, + html: string + } +} + + + +export async function RawDocuments(folder: string | undefined, returnDocs?: GithubFile[]): Promise; +export async function RawDocuments(url: string | undefined, returnDocs?: GithubFile[]): Promise; +export async function RawDocuments(a: string | undefined, returnDocs?: GithubFile[]): Promise { + if (!returnDocs) returnDocs = [] + + let fetchURL = `https://api.github.com/repos/nickmackenzie/dont-get-zohod/contents/pages/${a}`; + if (isUrl(a)) { + fetchURL = a; + } + + try { + const response = await fetch(fetchURL); + const data = await response.json(); + + for (const item of data) { + if (item.type === "dir") { + // Recursively fetch documents for directories + returnDocs = await RawDocuments(item.url, returnDocs); + } else { + // Add documents to the result array for files + returnDocs.push(item); + } + } + } catch (error) { + console.error('Error fetching file list:', error); + } + + return returnDocs; + } export const DocumentCards = (props) => { @@ -16,8 +58,12 @@ export const DocumentCards = (props) => { const func = async () => { const docList = [] const documents = await RawDocuments(props.folder) - for (const document of documents.filter(doc => doc.name.includes(".md"))) { - const metadata = await FetchContent(document.git_url); + if (Object.keys(documents).includes("message")) return + for (const document of documents.filter(doc => { return doc.name.includes(".md") && !doc.name.includes("index") })) { + let metadata = await FetchContent(document.git_url); + if (typeof metadata == 'undefined') { + metadata = { title: document.name.replace(/.[^\/\.]+$/, '') } + } docList.push({ ...document, ...metadata }) } setDocuments(docList); @@ -74,4 +120,14 @@ const extractMetadataFromMarkdown = (markdown) => { }, {}); return metadataObject; -}; \ No newline at end of file +}; + +const isUrl = (urlString: string) => { + var urlPattern = new RegExp('^(https?:\\/\\/)?' + // validate protocol + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // validate domain name + '((\\d{1,3}\\.){3}\\d{1,3}))' + // validate OR ip (v4) address + '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // validate port and path + '(\\?[;&a-z\\d%_.~+=-]*)?' + // validate query string + '(\\#[-a-z\\d_]*)?$', 'i'); // validate fragment locator + return !!urlPattern.test(urlString); +} \ No newline at end of file diff --git a/pages/catalyst/index.mdx b/pages/catalyst/index.mdx index 8420768..e01130c 100644 --- a/pages/catalyst/index.mdx +++ b/pages/catalyst/index.mdx @@ -1,14 +1,16 @@ -import {CatalystIcon} from '../../components/zohoIcons' +import { CatalystIcon } from "../../components/zohoIcons"; -import { Callout } from 'nextra/components' +import { Callout } from "nextra/components"; + +import { DocumentCards } from "../../components/docList"; # Catalyst - - This page is still under development. - +This page is still under development. + + ## Quick Links - [API](https://docs.catalyst.zoho.com/en/api/introduction/overview-and-prerequisites/) -- [Knowledge Base](https://docs.catalyst.zoho.com/en/faq/general/) \ No newline at end of file +- [Knowledge Base](https://docs.catalyst.zoho.com/en/faq/general/) diff --git a/pages/commerce/_meta.json b/pages/commerce/_meta.json index 2a6921b..941708c 100644 --- a/pages/commerce/_meta.json +++ b/pages/commerce/_meta.json @@ -1,3 +1,6 @@ -{ - "showUnit":"Show Unit on Website" +{ + "index": { + "display": "hidden" + }, + "showUnit": "Show Unit on Website" } diff --git a/pages/commerce/index.mdx b/pages/commerce/index.mdx new file mode 100644 index 0000000..e41a1d2 --- /dev/null +++ b/pages/commerce/index.mdx @@ -0,0 +1,13 @@ +import {CommerceIcon} from '../../components/zohoIcons' + +import { Callout } from 'nextra/components' + +import {DocumentCards} from '../../components/docList' + +# Commerce + +This page is still under development.. + + + +## Quick Links diff --git a/pages/creator/_meta.json b/pages/creator/_meta.json new file mode 100644 index 0000000..5e6a93c --- /dev/null +++ b/pages/creator/_meta.json @@ -0,0 +1,5 @@ +{ + "index": { + "display": "hidden" + } +} diff --git a/pages/creator/index.mdx b/pages/creator/index.mdx new file mode 100644 index 0000000..ffa5d74 --- /dev/null +++ b/pages/creator/index.mdx @@ -0,0 +1,15 @@ +import {CreatorIcon} from '../../components/zohoIcons' + +import { Callout } from 'nextra/components' + +import {DocumentCards} from '../../components/docList' + +# Creator + + + This page is still under development.. + + + + +## Quick Links \ No newline at end of file diff --git a/pages/crm/index.mdx b/pages/crm/index.mdx index e12d45a..276a212 100644 --- a/pages/crm/index.mdx +++ b/pages/crm/index.mdx @@ -1,13 +1,17 @@ import {CrmIcon} from '../../components/zohoIcons' import { Callout } from 'nextra/components' + +import {DocumentCards} from '../../components/docList' # CRM - This page is still under development. + This page is still under development.. + + ## Quick Links - [API](https://www.zoho.com/crm/developer/docs/api/v6/) diff --git a/pages/deluge/index.mdx b/pages/deluge/index.mdx new file mode 100644 index 0000000..15818c4 --- /dev/null +++ b/pages/deluge/index.mdx @@ -0,0 +1,13 @@ +import {DelugeIcon} from '../../components/zohoIcons' + +import { Callout } from 'nextra/components' + +import {DocumentCards} from '../../components/docList' + +# Deluge + +This page is still under development.. + + + +## Quick Links diff --git a/pages/deluge/timeDates/_meta.json b/pages/deluge/timeDates/_meta.json deleted file mode 100644 index 374fefd..0000000 --- a/pages/deluge/timeDates/_meta.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "FormatForCRM":"Format Date For CRM" -} \ No newline at end of file diff --git a/pages/desk/_meta.json b/pages/desk/_meta.json new file mode 100644 index 0000000..539dbed --- /dev/null +++ b/pages/desk/_meta.json @@ -0,0 +1,6 @@ +{ + "index": { + "display": "hidden" + }, + "searchWithCustomField": "Searching Zoho Desk with Custom Field Values" +} diff --git a/pages/desk/index.mdx b/pages/desk/index.mdx new file mode 100644 index 0000000..825a5c1 --- /dev/null +++ b/pages/desk/index.mdx @@ -0,0 +1,13 @@ +import {DeskIcon} from '../../components/zohoIcons' + +import { Callout } from 'nextra/components' + +import {DocumentCards} from '../../components/docList' + +# Desk + +This page is still under development.. + + + +## Quick Links diff --git a/pages/desk/searchWithCustomField.md b/pages/desk/searchWithCustomField.md index a1dc49d..b93b093 100644 --- a/pages/desk/searchWithCustomField.md +++ b/pages/desk/searchWithCustomField.md @@ -1,6 +1,10 @@ +--- +title: Searching Zoho Desk with Custom Field Values +--- + # Searching Zoho Desk with Custom Field Values -If you're like me, you may have spent a long time trying to find a way to search Zoho Desk records with the search criteria being a custom field value. The trick is simple, but it took some time with Zoho official support to find the answer. +If you're like me, you may have spent a long time trying to find a way to search Zoho Desk records with the search criteria being a custom field value. The trick is simple, but it took some time with Zoho official support to find the answer. Here's how you should set up your search criteria. No matter the name of your custom field, you have to use the key "customField1" where the value is a string-formatted version of the customfield name and value, like this: @@ -12,6 +16,7 @@ criteriaMap.put("customField1",":"); You can also see docs for this function - https://www.zoho.com/deluge/help/desk/search-records.html ## Example + ``` // Step 1 - first you must specify your orgId. You can find your orgId in Zoho Desk by going to settings > API > scroll all the way down to the bottom of the page. @@ -31,4 +36,4 @@ deskResponse = zoho.desk.searchRecords(orgId,"Accounts",criteriaMap,1,5," - } - title="Deluge" - href="" - onClick={(e) => e.preventDefault()} - /> + } title="Deluge" href="/deluge" /> ### Apps - } - title="Catalyst" - href="" - onClick={(e) => e.preventDefault()} - /> - } - title="Commerce" - href="" - onClick={(e) => e.preventDefault()} - /> - } - title="Creator" - href="" - onClick={(e) => e.preventDefault()} - /> - } title="CRM" href="" onClick={(e) => e.preventDefault()} /> - } - title="Desk" - href="" - onClick={(e) => e.preventDefault()} - /> - } - title="Sites" - href="" - onClick={(e) => e.preventDefault()} - /> + } title="Catalyst" href="/catalyst" /> + } title="Commerce" href="/commerce" /> + } title="Creator" href="/creator" /> + } title="CRM" href="/crm" /> + } title="Desk" href="/desk" /> + } title="Sites" href="/sites" /> ### Resources & Tools diff --git a/pages/sites/_meta.json b/pages/sites/_meta.json index af67bc7..a6f5e9e 100644 --- a/pages/sites/_meta.json +++ b/pages/sites/_meta.json @@ -1,6 +1,9 @@ { - "custom404": "Custom 404 Page", - "customFonts": "Custom Fonts", - "listBlogPosts": "List Blog Posts on Any Page", - "paragraphExpansion": "Paragraph Expansion (Show More/Less)" + "index": { + "display": "hidden" + }, + "custom404": "Custom 404 Page", + "customFonts": "Custom Fonts", + "listBlogPosts": "List Blog Posts on Any Page", + "paragraphExpansion": "Paragraph Expansion (Show More/Less)" } diff --git a/pages/sites/index.mdx b/pages/sites/index.mdx new file mode 100644 index 0000000..0bb0520 --- /dev/null +++ b/pages/sites/index.mdx @@ -0,0 +1,15 @@ +import {SitesIcon} from '../../components/zohoIcons' + +import { Callout } from 'nextra/components' + +import {DocumentCards} from '../../components/docList' + +# Sites + + + This page is still under development.. + + + + +## Quick Links