Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add search #2589

Merged
merged 18 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 54 additions & 14 deletions .all-sponsorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"role": "ADMIN",
"isActive": true,
"totalAmountDonated": 0,
"lastTransactionAt": "2020-11-08 20:07",
"lastTransactionAt": "2020-11-30 16:17",
"lastTransactionAmount": 0,
"profile": "https://opencollective.com/segun-adebayo",
"name": "Segun Adebayo",
Expand Down Expand Up @@ -206,7 +206,7 @@
"type": "USER",
"role": "BACKER",
"tier": "Bronze Backer 🥉",
"isActive": false,
"isActive": true,
"totalAmountDonated": 70,
"currency": "USD",
"lastTransactionAt": "2020-10-01 05:15",
Expand Down Expand Up @@ -659,13 +659,13 @@
"lastTransactionAmount": 5,
"profile": "https://opencollective.com/andrew-miracle",
"name": "Andrew Miracle",
"company": null,
"description": null,
"company": "",
"description": "building for the community",
"image": "/avatars/122920.jpg",
"email": null,
"twitter": null,
"github": null,
"website": null
"twitter": "https://twitter.com/koolamusic",
"github": "https://github.com/koolamusic",
"website": "https://andrewmiracle.com"
},
{
"MemberId": 123683,
Expand Down Expand Up @@ -736,7 +736,7 @@
"type": "USER",
"role": "BACKER",
"tier": "Silver Backer 🥈",
"isActive": false,
"isActive": true,
"totalAmountDonated": 50,
"currency": "USD",
"lastTransactionAt": "2020-10-02 15:30",
Expand Down Expand Up @@ -791,6 +791,46 @@
"twitter": "https://twitter.com/ajitsonlion",
"github": null,
"website": "https://www.blog.ajitsonlion.com"
},
{
"MemberId": 140693,
"createdAt": "2020-11-15 03:48",
"type": "USER",
"role": "BACKER",
"isActive": true,
"totalAmountDonated": 5,
"currency": "USD",
"lastTransactionAt": "2020-11-15 03:48",
"lastTransactionAmount": 5,
"profile": "https://opencollective.com/brady-dukart",
"name": "Brady Dukart",
"company": null,
"description": null,
"image": "/avatars/140693.jpg",
"email": null,
"twitter": null,
"github": null,
"website": null
},
{
"MemberId": 141165,
"createdAt": "2020-11-16 22:43",
"type": "USER",
"role": "BACKER",
"isActive": true,
"totalAmountDonated": 5,
"currency": "USD",
"lastTransactionAt": "2020-11-16 22:43",
"lastTransactionAmount": 5,
"profile": "https://opencollective.com/nathan-simpson",
"name": "Nathan Simpson",
"company": null,
"description": null,
"image": "/avatars/141165.jpg",
"email": null,
"twitter": null,
"github": null,
"website": null
}
],
"companies": [
Expand All @@ -801,7 +841,7 @@
"role": "HOST",
"isActive": true,
"totalAmountDonated": 0,
"lastTransactionAt": "2020-11-08 20:07",
"lastTransactionAt": "2020-11-30 16:17",
"lastTransactionAmount": 0,
"profile": "https://opencollective.com/opensource",
"name": "Open Source Collective 501(c)(6)",
Expand All @@ -820,7 +860,7 @@
"role": "BACKER",
"isActive": true,
"totalAmountDonated": 18,
"lastTransactionAt": "2020-11-08 20:07",
"lastTransactionAt": "2020-11-30 16:17",
"lastTransactionAmount": 0,
"profile": "https://opencollective.com/triplebyte",
"name": "Triplebyte",
Expand All @@ -839,7 +879,7 @@
"role": "BACKER",
"isActive": true,
"totalAmountDonated": 15,
"lastTransactionAt": "2020-11-08 20:07",
"lastTransactionAt": "2020-11-30 16:17",
"lastTransactionAmount": 0,
"profile": "https://opencollective.com/thinkmill",
"name": "Thinkmill",
Expand Down Expand Up @@ -897,7 +937,7 @@
"type": "ORGANIZATION",
"role": "BACKER",
"tier": "sponsor",
"isActive": false,
"isActive": true,
"totalAmountDonated": 820,
"currency": "USD",
"lastTransactionAt": "2020-10-01 05:09",
Expand Down Expand Up @@ -1064,9 +1104,9 @@
"type": "ORGANIZATION",
"role": "BACKER",
"isActive": true,
"totalAmountDonated": 50,
"totalAmountDonated": 100,
"currency": "USD",
"lastTransactionAt": "2020-09-15 08:27",
"lastTransactionAt": "2020-11-22 17:23",
"lastTransactionAmount": 50,
"profile": "https://opencollective.com/ada-school",
"name": "ADA School",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/cold-ants-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chakra-ui/layout": patch
---

fix prop type interface for stack
2 changes: 1 addition & 1 deletion examples/next-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"@chakra-ui/react": "1.0.1",
"next": "^10.0.1",
"next": "^10.0.3",
"react": "^17.0.1",
"react-dom": "^17.0.1"
}
Expand Down
4 changes: 2 additions & 2 deletions examples/nextjs-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"@types/react": "^16.9.53",
"@types/react-dom": "^16.9.8",
"faker": "^5.1.0",
"next": "^10.0.1",
"next": "^10.0.3",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-icons": "^3.11.0",
"react-icons": "^4.1.0",
"typescript": "^4.0.5"
},
"repository": {
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"check:pkgs": "manypkg check",
"fix:pkgs": "manypkg fix",
"version:pkgs": "changeset version",
"postinstall": "yarn check:pkgs",
"postinstall": "yarn fix:pkgs",
"contributors:add": "all-contributors add",
"contributors:gen": "all-contributors generate",
"prestart": "yarn && yarn bootstrap",
Expand All @@ -45,13 +45,14 @@
"build:storybook": "build-storybook && sb extract",
"members:gen": "ts-node scripts/all-members.ts",
"avatars:gen": "ts-node scripts/avatars.ts",
"search-meta:gen": "ts-node scripts/get-search-meta.ts",
"create-pkg": "node scripts/create-package.js",
"prerelease": "yarn build",
"release": "changeset publish",
"docs": "yarn workspace @chakra-ui/docs",
"docs:deploy": "yarn build && yarn docs:build-ci && cp -r website/public .",
"docs:build-ci": "yarn members:gen && yarn docs:build",
"docs:build": "yarn avatars:gen && yarn docs build",
"docs:build": "yarn avatars:gen && yarn search-meta:gen && yarn docs build",
"docs:dev": "yarn avatars:gen && yarn docs dev",
"docs:start": "yarn docs start",
"dedup": "yarn-deduplicate --strategy highest yarn.lock"
Expand Down Expand Up @@ -131,6 +132,7 @@
"lerna": "^3.22.1",
"lint-staged": "^10.4.2",
"listr": "^0.14.3",
"markdown-toc": "^1.2.0",
"mkdirp": "^1.0.4",
"ncp": "^2.0.0",
"node-fetch": "^2.6.1",
Expand All @@ -139,7 +141,7 @@
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-hook-form": "^6.11.3",
"react-icons": "^3.11.0",
"react-icons": "^4.1.0",
"react-lorem-component": "^0.13.0",
"react-router-dom": "^5.2.0",
"react-spinners": "^0.9.0",
Expand All @@ -151,6 +153,7 @@
"ts-jest": "^26.4.2",
"ts-node": "^9.0.0",
"typescript": "^4.0.5",
"uuid": "8.3.1",
"yarn-deduplicate": "^3.0.0"
}
}
5 changes: 2 additions & 3 deletions packages/layout/src/stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import {
ChakraComponent,
forwardRef,
HTMLChakraProps,
PropsOf,
SystemProps,
} from "@chakra-ui/system"
import { cx, getValidChildren, __DEV__ } from "@chakra-ui/utils"
import * as React from "react"
import { getDividerStyles, getStackStyles, selector } from "./stack.utils"
import type { StackDirection } from "./stack.utils"
import { getDividerStyles, getStackStyles, selector } from "./stack.utils"

export type { StackDirection }

Expand Down Expand Up @@ -86,7 +85,7 @@ export const StackItem: ChakraComponent<"div"> = (props) => (
/>
)

export interface StackProps extends PropsOf<typeof chakra.div>, StackOptions {}
export interface StackProps extends HTMLChakraProps<"div">, StackOptions {}

/**
* Stacks help you easily create flexible and automatically distributed layouts
Expand Down
94 changes: 94 additions & 0 deletions scripts/get-search-meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { parseMarkdownFile, fileToPath, removePrefix } from "@docusaurus/utils"
import path from "path"
import toc from "markdown-toc"
import { v4 as uuid } from "uuid"
import shell from "shelljs"
import fs from "graceful-fs"
import prettier from "prettier"

interface ResultType {
content: string
id: string
url: string
type: "lvl1" | "lvl2" | "lvl3"
hierarchy: {
lvl1: string | null
lvl2?: string | null
lvl3?: string | null
}
}

interface TOCResultItem {
content: string
slug: string
lvl: 1 | 2 | 3
i: number
seen: number
}

const websiteRoot = "website/pages"

async function getMDXMeta(file: string) {
const { content, frontMatter } = await parseMarkdownFile(file)
const tableOfContent = toc(content)
const json = tableOfContent.json as TOCResultItem[]
const slug = fileToPath(file)
.replace(`/${websiteRoot}`, "")
.replace(process.cwd(), "")

const result: ResultType[] = []

result.push({
content: frontMatter.title,
id: uuid(),
type: "lvl1",
url: removePrefix(slug, "/"),
hierarchy: {
lvl1: frontMatter.title,
},
})

json.forEach((item, index) => {
result.push({
content: item.content,
id: uuid(),
type: `lvl${item.lvl}` as any,
url: removePrefix(slug, "/") + `#${item.slug}`,
hierarchy: {
lvl1: frontMatter.title,
lvl2: item.lvl === 2 ? item.content : json[index - 1]?.content ?? null,
lvl3: item.lvl === 3 ? item.content : null,
},
})
})

return result
}

async function getSearchMeta() {
let json: any = []

const files = shell
.ls("-R", websiteRoot)
.map((file) => path.join(process.cwd(), websiteRoot, file))
.filter((file) => file.endsWith(".mdx"))

for (const file of files) {
let result: any[] = []
try {
result = await getMDXMeta(file)
json.push(...result)
} catch (error) {}
}

json = prettier.format(JSON.stringify(json), { parser: "json" })
const outPath = path.join(
process.cwd(),
"website/configs",
"search-meta.json",
)
fs.writeFileSync(outPath, json)
console.log("Search meta is ready ✅")
}

getSearchMeta()