Skip to content

Commit

Permalink
Created recursive document listing component + created app index pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dmick92 committed Jan 19, 2024
1 parent 3cf3584 commit f3d345d
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 64 deletions.
74 changes: 65 additions & 9 deletions components/docList/index.tsx
Original file line number Diff line number Diff line change
@@ -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<GithubFile[]>;
export async function RawDocuments(url: string | undefined, returnDocs?: GithubFile[]): Promise<GithubFile[]>;
export async function RawDocuments(a: string | undefined, returnDocs?: GithubFile[]): Promise<GithubFile[]> {
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) => {
Expand All @@ -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);
Expand Down Expand Up @@ -74,4 +120,14 @@ const extractMetadataFromMarkdown = (markdown) => {
}, {});

return metadataObject;
};
};

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);
}
14 changes: 8 additions & 6 deletions pages/catalyst/index.mdx
Original file line number Diff line number Diff line change
@@ -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";

# <CatalystIcon style={{marginBottom:'-8px'}} /> Catalyst

<Callout emoji="🚧">
This page is still under development.
</Callout>
<Callout emoji="🚧">This page is still under development.</Callout>

<DocumentCards folder="catalyst" />

## Quick Links

- [API](https://docs.catalyst.zoho.com/en/api/introduction/overview-and-prerequisites/)
- [Knowledge Base](https://docs.catalyst.zoho.com/en/faq/general/)
- [Knowledge Base](https://docs.catalyst.zoho.com/en/faq/general/)
7 changes: 5 additions & 2 deletions pages/commerce/_meta.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"showUnit":"Show Unit on Website"
{
"index": {
"display": "hidden"
},
"showUnit": "Show Unit on Website"
}
13 changes: 13 additions & 0 deletions pages/commerce/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {CommerceIcon} from '../../components/zohoIcons'

import { Callout } from 'nextra/components'

import {DocumentCards} from '../../components/docList'

# <CommerceIcon style={{marginBottom:'-8px'}} /> Commerce

<Callout emoji="🚧">This page is still under development..</Callout>

<DocumentCards folder="commerce" />

## Quick Links
5 changes: 5 additions & 0 deletions pages/creator/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"index": {
"display": "hidden"
}
}
15 changes: 15 additions & 0 deletions pages/creator/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {CreatorIcon} from '../../components/zohoIcons'

import { Callout } from 'nextra/components'

import {DocumentCards} from '../../components/docList'

# <CreatorIcon style={{marginBottom:'-8px'}} /> Creator

<Callout emoji="🚧">
This page is still under development..
</Callout>

<DocumentCards folder='creator' />

## Quick Links
6 changes: 5 additions & 1 deletion pages/crm/index.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import {CrmIcon} from '../../components/zohoIcons'

import { Callout } from 'nextra/components'

import {DocumentCards} from '../../components/docList'

# <CrmIcon style={{marginBottom:'-8px'}} /> CRM

<Callout emoji="🚧">
This page is still under development.
This page is still under development..
</Callout>

<DocumentCards folder='crm' />

## Quick Links

- [API](https://www.zoho.com/crm/developer/docs/api/v6/)
Expand Down
13 changes: 13 additions & 0 deletions pages/deluge/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {DelugeIcon} from '../../components/zohoIcons'

import { Callout } from 'nextra/components'

import {DocumentCards} from '../../components/docList'

# <DelugeIcon style={{marginBottom:'-8px'}} /> Deluge

<Callout emoji="🚧">This page is still under development..</Callout>

<DocumentCards folder="deluge" />

## Quick Links
3 changes: 0 additions & 3 deletions pages/deluge/timeDates/_meta.json

This file was deleted.

6 changes: 6 additions & 0 deletions pages/desk/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"index": {
"display": "hidden"
},
"searchWithCustomField": "Searching Zoho Desk with Custom Field Values"
}
13 changes: 13 additions & 0 deletions pages/desk/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {DeskIcon} from '../../components/zohoIcons'

import { Callout } from 'nextra/components'

import {DocumentCards} from '../../components/docList'

# <DeskIcon style={{marginBottom:'-8px'}} /> Desk

<Callout emoji="🚧">This page is still under development..</Callout>

<DocumentCards folder="desk" />

## Quick Links
9 changes: 7 additions & 2 deletions pages/desk/searchWithCustomField.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -12,6 +16,7 @@ criteriaMap.put("customField1","<Custom_Field_Name>:<Custom_Field_Value>");
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.
Expand All @@ -31,4 +36,4 @@ deskResponse = zoho.desk.searchRecords(orgId,"Accounts",criteriaMap,1,5,"<Your_O
info deskResponse;
```

Contributed by Daniel Whiteside - [email protected] - June 2023
Contributed by Daniel Whiteside - [email protected] - June 2023
44 changes: 7 additions & 37 deletions pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,18 @@ This is a community driven repository for Zoho developers to share tips & tricks
Some scripts aren't app specific. Check out the Deluge section for generic Deluge scripts.

<Cards>
<Card
icon={<DelugeIcon />}
title="Deluge"
href=""
onClick={(e) => e.preventDefault()}
/>
<Card icon={<DelugeIcon />} title="Deluge" href="/deluge" />
</Cards>

### Apps

<Cards>
<Card
icon={<CatalystIcon />}
title="Catalyst"
href=""
onClick={(e) => e.preventDefault()}
/>
<Card
icon={<CommerceIcon />}
title="Commerce"
href=""
onClick={(e) => e.preventDefault()}
/>
<Card
icon={<CreatorIcon />}
title="Creator"
href=""
onClick={(e) => e.preventDefault()}
/>
<Card icon={<CrmIcon />} title="CRM" href="" onClick={(e) => e.preventDefault()} />
<Card
icon={<DeskIcon />}
title="Desk"
href=""
onClick={(e) => e.preventDefault()}
/>
<Card
icon={<SitesIcon />}
title="Sites"
href=""
onClick={(e) => e.preventDefault()}
/>
<Card icon={<CatalystIcon />} title="Catalyst" href="/catalyst" />
<Card icon={<CommerceIcon />} title="Commerce" href="/commerce" />
<Card icon={<CreatorIcon />} title="Creator" href="/creator" />
<Card icon={<CrmIcon />} title="CRM" href="/crm" />
<Card icon={<DeskIcon />} title="Desk" href="/desk" />
<Card icon={<SitesIcon />} title="Sites" href="/sites" />
</Cards>

### Resources & Tools
11 changes: 7 additions & 4 deletions pages/sites/_meta.json
Original file line number Diff line number Diff line change
@@ -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)"
}
15 changes: 15 additions & 0 deletions pages/sites/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {SitesIcon} from '../../components/zohoIcons'

import { Callout } from 'nextra/components'

import {DocumentCards} from '../../components/docList'

# <SitesIcon style={{marginBottom:'-8px'}} /> Sites

<Callout emoji="🚧">
This page is still under development..
</Callout>

<DocumentCards folder='sites' />

## Quick Links

0 comments on commit f3d345d

Please sign in to comment.