diff --git a/packages/guides/README.md b/packages/guides/README.md new file mode 100644 index 000000000000..b989197b5750 --- /dev/null +++ b/packages/guides/README.md @@ -0,0 +1,45 @@ +# @graphprotocol/guides Demo + +This package contains a standalone Next.js application to demonstrate a filterable and searchable "Guides" page, inspired by Vercel's guides section. It is intended for internal demo purposes and can later be integrated into the main The Graph documentation site. + +## Features + +- Filter guides by Products, Guide Types, and Difficulty. +- Fuzzy search across guide titles, descriptions, products, and types. +- Guide detail pages displaying content (currently stubs). +- Styled with Tailwind CSS. + +## Running the Demo + +1. **Install dependencies (from the project root):** + ```bash + pnpm install + ``` + +2. **Start the development server for this package only:** + ```bash + pnpm --filter @graphprotocol/guides dev + ``` + +3. **Open your browser to:** [http://localhost:3100/guides](http://localhost:3100/guides) + +## Structure + +- `pages/guides/index.tsx`: The main browse/filter page. +- `pages/guides/[slug].tsx`: Individual guide detail page. +- `data/guides.json`: Sample guide data (includes titles, descriptions, categories, content stubs, etc.). +- `components/`: (Currently minimal, but can house reusable UI parts). +- `styles/`: Global CSS and Tailwind setup. +- `public/`: Static assets (if any). +``` + +## Integration into Main Docs + +To integrate this into the main `@graphprotocol/docs` Nextra website: + +1. Copy the relevant page components (primarily `pages/guides/index.tsx` and `pages/guides/[slug].tsx`) into the `website/pages/` directory of the main documentation site. +2. Adapt the data loading (`guides.json`) and styling (Tailwind/global CSS) to fit the existing Nextra structure. +3. Ensure any shared components or utilities are correctly imported or moved. +4. The filtering logic and Fuse.js setup can be largely reused. + +This package (`@graphprotocol/guides`) itself would then likely not be directly imported as a library, but its code would serve as the basis for the new section within the main documentation app. \ No newline at end of file diff --git a/packages/guides/data/guides.json b/packages/guides/data/guides.json new file mode 100644 index 000000000000..9f7367ecef4c --- /dev/null +++ b/packages/guides/data/guides.json @@ -0,0 +1,145 @@ +[ + { + "title": "Building Subgraphs 101", + "slug": "building-subgraphs-101", + "description": "Learn the basics of creating a subgraph on The Graph network.", + "products": ["Subgraphs", "The Graph Network"], + "date": "2024-05-18", + "author": "Graph Docs Team", + "types": ["Blog"], + "difficulty": "Easy", + "content": "# Building Subgraphs 101\n\nThis is a stub page for the guide content..." + }, + { + "title": "Indexing Smart Contracts with The Graph", + "slug": "indexing-smart-contracts", + "description": "Step-by-step video tutorial for indexing contracts using Graph CLI.", + "products": ["Graph Node", "Subgraphs"], + "date": "2024-03-02", + "author": "Graph Protocol", + "types": ["Video", "Workshop"], + "difficulty": "Intermediate", + "content": "# Indexing Smart Contracts with The Graph\nVideo embed or details here..." + }, + { + "title": "Using Graph Client in React", + "slug": "using-graph-client-react", + "description": "How to query subgraphs efficiently in a React front-end.", + "products": ["Token API", "Subgraphs"], + "date": "2023-12-10", + "author": "Edge & Node", + "types": ["Blog", "Repository"], + "difficulty": "Easy", + "content": "# Using Graph Client in React\nContent placeholder." + }, + { + "title": "Substreams Rust Workshop", + "slug": "substreams-rust-workshop", + "description": "Hands-on workshop on authoring Substreams modules in Rust.", + "products": ["Substreams"], + "date": "2024-01-15", + "author": "StreamingFast", + "types": ["Workshop", "Video"], + "difficulty": "Advanced", + "content": "# Substreams Rust Workshop\nContent stub." + }, + { + "title": "Deploying Graph Node on Kubernetes", + "slug": "deploying-graph-node-k8s", + "description": "Guide to deploy an indexing node on Kubernetes cluster.", + "products": ["Graph Node", "The Graph Network"], + "date": "2024-02-20", + "author": "Graph Community", + "types": ["Blog"], + "difficulty": "Advanced", + "content": "# Deploying Graph Node on Kubernetes\nStub article." + }, + { + "title": "Building Token API Queries", + "slug": "building-token-api-queries", + "description": "Learn to query token metadata using The Graph Token API.", + "products": ["Token API"], + "date": "2024-04-02", + "author": "Graph Docs Team", + "types": ["Blog"], + "difficulty": "Intermediate", + "content": "# Building Token API Queries\nStub." + }, + { + "title": "Intro to The Graph Network", + "slug": "intro-graph-network", + "description": "High-level overview of how the decentralized network works.", + "products": ["The Graph Network"], + "date": "2023-11-05", + "author": "Graph Foundation", + "types": ["Video"], + "difficulty": "Easy", + "content": "# Intro to The Graph Network\nStub." + }, + { + "title": "Optimizing Subgraph Performance", + "slug": "optimizing-subgraph-performance", + "description": "Best practices for faster indexing and query responses.", + "products": ["Subgraphs"], + "date": "2024-05-01", + "author": "Edge & Node", + "types": ["Blog"], + "difficulty": "Intermediate", + "content": "# Optimizing Subgraph Performance\nStub." + }, + { + "title": "GraphQL Basics for The Graph", + "slug": "graphql-basics", + "description": "Essential GraphQL concepts every Graph builder should know.", + "products": ["Subgraphs", "Token API"], + "date": "2023-10-01", + "author": "Graph Docs Team", + "types": ["Blog", "Video"], + "difficulty": "Easy", + "content": "# GraphQL Basics\nStub." + }, + { + "title": "Migrating from Hosted Service to Network", + "slug": "migrating-to-network", + "description": "Step-by-step migration strategy.", + "products": ["The Graph Network", "Subgraphs"], + "date": "2024-06-10", + "author": "Graph Ops", + "types": ["Blog", "Workshop"], + "difficulty": "Advanced", + "content": "# Migration Guide\nStub." + }, + { + "title": "Query Token Prices Using Substreams", + "slug": "token-prices-substreams", + "description": "Create a Substreams pipeline for token price data.", + "products": ["Substreams", "Token API"], + "date": "2024-04-25", + "author": "StreamingFast", + "types": ["Repository"], + "difficulty": "Intermediate", + "content": "# Token Prices Substreams\nStub." + }, + { + "title": "Graph Node Metrics and Monitoring", + "slug": "graph-node-metrics", + "description": "Expose Prometheus metrics from Graph Node and set up Grafana dashboards.", + "products": ["Graph Node"], + "date": "2024-02-28", + "author": "Graph Community", + "types": ["Blog", "Repository"], + "difficulty": "Advanced", + "content": "# Graph Node Metrics\nStub." + }, + { + "title": "Deploying a Subgraph on Arbitrum", + "slug": "deploying-subgraph-arbitrum", + "description": "End-to-end guide to deploy a subgraph for Arbitrum network.", + "products": ["Subgraphs"], + "date": "2024-05-30", + "author": "Graph Docs Team", + "types": ["Blog"], + "difficulty": "Intermediate", + "content": "# Deploying Subgraph on Arbitrum\nStub." + } +] \ No newline at end of file diff --git a/packages/guides/next-env.d.ts b/packages/guides/next-env.d.ts new file mode 100644 index 000000000000..a4a7b3f5cfa2 --- /dev/null +++ b/packages/guides/next-env.d.ts @@ -0,0 +1,5 @@ +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. diff --git a/packages/guides/next.config.js b/packages/guides/next.config.js new file mode 100644 index 000000000000..deb4656b3b05 --- /dev/null +++ b/packages/guides/next.config.js @@ -0,0 +1,9 @@ +// @ts-check + +/** @type {import('next').NextConfig} */ +const nextConfig = { + reactStrictMode: true, + trailingSlash: true, +}; + +export default nextConfig; \ No newline at end of file diff --git a/packages/guides/package.json b/packages/guides/package.json new file mode 100644 index 000000000000..c8b6421e8c6b --- /dev/null +++ b/packages/guides/package.json @@ -0,0 +1,26 @@ +{ + "name": "@graphprotocol/guides", + "version": "0.1.0", + "private": true, + "main": "dist/index.js", + "types": "dist/index.d.ts", + "files": ["dist"], + "scripts": { + "dev": "next dev -p 3100", + "build": "next build", + "preview": "next start -p 3100", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "next": "^14.2.28", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "fuse.js": "^7.0.0" + }, + "devDependencies": { + "typescript": "^5.8.3", + "tailwindcss": "^3.4.17", + "postcss": "^8.5.3", + "autoprefixer": "^10.4.21" + } +} \ No newline at end of file diff --git a/packages/guides/pages/_app.tsx b/packages/guides/pages/_app.tsx new file mode 100644 index 000000000000..6c42fd075e7c --- /dev/null +++ b/packages/guides/pages/_app.tsx @@ -0,0 +1,6 @@ +import '@/styles/globals.css'; +import type { AppProps } from 'next/app'; + +export default function App({ Component, pageProps }: AppProps) { + return ; +} \ No newline at end of file diff --git a/packages/guides/pages/guides/[slug].tsx b/packages/guides/pages/guides/[slug].tsx new file mode 100644 index 000000000000..8ea0f97ae79e --- /dev/null +++ b/packages/guides/pages/guides/[slug].tsx @@ -0,0 +1,59 @@ +import { GetStaticPaths, GetStaticProps } from 'next'; +import Link from 'next/link'; +import guides from '../../data/guides.json'; + +interface Guide { + title: string; + slug: string; + description: string; + products: string[]; + date: string; + author: string; + types: string[]; + difficulty: string; + content: string; + url?: string; +} + +export const getStaticPaths: GetStaticPaths = async () => { + return { + paths: (guides as Guide[]).map((g) => ({ params: { slug: g.slug } })), + fallback: false, + }; +}; + +export const getStaticProps: GetStaticProps = async ({ params }) => { + const guide = (guides as Guide[]).find((g) => g.slug === params?.slug); + if (!guide) return { notFound: true }; + return { + props: { guide }, + }; +}; + +export default function GuidePage({ guide }: { guide: Guide }) { + return ( +
+ ← Back to Guides +

{guide.title}

+

{guide.description}

+
+ {guide.products.map((p) => ( + {p} + ))} + {guide.types.map((t) => ( + {t} + ))} + {guide.difficulty} + {new Date(guide.date).toLocaleDateString()} +
+
') }} /> + {guide.url && ( +

+ + View original resource + +

+ )} +
+ ); +} \ No newline at end of file diff --git a/packages/guides/pages/guides/index.tsx b/packages/guides/pages/guides/index.tsx new file mode 100644 index 000000000000..3d1babad6c2e --- /dev/null +++ b/packages/guides/pages/guides/index.tsx @@ -0,0 +1,149 @@ +import React, { useMemo, useState } from 'react'; +import Fuse from 'fuse.js'; +import guidesData from '../../data/guides.json'; +import Link from 'next/link'; + +interface Guide { + title: string; + slug: string; + description: string; + products: string[]; + date: string; + author: string; + types: string[]; + url?: string; + difficulty: string; + content: string; +} + +const PRODUCTS = [ + 'Subgraphs', + 'Substreams', + 'Token API', + 'The Graph Network', + 'Graph Node', +] as const; + +const GUIDE_TYPES = ['Blog', 'Repository', 'Video', 'Workshop'] as const; + +const DIFFICULTIES = ['Easy', 'Intermediate', 'Advanced'] as const; + +const fuse = new Fuse(guidesData as Guide[], { + includeScore: true, + threshold: 0.4, + keys: ['title', 'description', 'products', 'types'], +}); + +export default function GuidesPage() { + const [query, setQuery] = useState(''); + const [selectedProducts, setSelectedProducts] = useState>(new Set()); + const [selectedTypes, setSelectedTypes] = useState>(new Set()); + const [selectedDifficulties, setSelectedDifficulties] = useState>(new Set()); + + const guides = useMemo(() => { + let filtered: Guide[] = guidesData as Guide[]; + + if (selectedProducts.size) { + filtered = filtered.filter((g) => g.products.some((p) => selectedProducts.has(p))); + } + if (selectedTypes.size) { + filtered = filtered.filter((g) => g.types.some((t) => selectedTypes.has(t))); + } + if (selectedDifficulties.size) { + filtered = filtered.filter((g) => selectedDifficulties.has(g.difficulty)); + } + if (query.trim()) { + return fuse + .search(query) + .map((r) => r.item) + .filter((g) => filtered.includes(g)); + } + return filtered; + }, [query, selectedProducts, selectedTypes, selectedDifficulties]); + + const toggle = (value: string, set: React.Dispatch>>) => { + set((prev) => { + const next = new Set(prev); + next.has(value) ? next.delete(value) : next.add(value); + return next; + }); + }; + + const Checkbox = ({ label, checked, onChange }: { label: string; checked: boolean; onChange(): void }) => ( +
  • + + {label} +
  • + ); + + return ( +
    + +
    +
    + setQuery(e.target.value)} + className="w-full md:w-1/2 border rounded px-3 py-2" + /> +
    +
      + {guides.map((g) => ( +
    • + +

      {g.title}

      + +

      {g.description}

      +
      + {g.products.map((c) => ( + + {c} + + ))} + {g.types.map((t) => ( + + {t} + + ))} + {new Date(g.date).toLocaleDateString()} + {g.difficulty} +
      +
    • + ))} +
    +
    +
    + ); +} \ No newline at end of file diff --git a/packages/guides/postcss.config.mjs b/packages/guides/postcss.config.mjs new file mode 100644 index 000000000000..a99a89c7ea64 --- /dev/null +++ b/packages/guides/postcss.config.mjs @@ -0,0 +1,6 @@ +export default { + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, +}; \ No newline at end of file diff --git a/packages/guides/src/index.ts b/packages/guides/src/index.ts new file mode 100644 index 000000000000..9d1599374fa6 --- /dev/null +++ b/packages/guides/src/index.ts @@ -0,0 +1 @@ +export const hello = (): string => 'Hello from @graphprotocol/guides'; \ No newline at end of file diff --git a/packages/guides/styles/globals.css b/packages/guides/styles/globals.css new file mode 100644 index 000000000000..de4d11a2e835 --- /dev/null +++ b/packages/guides/styles/globals.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; \ No newline at end of file diff --git a/packages/guides/tailwind.config.mjs b/packages/guides/tailwind.config.mjs new file mode 100644 index 000000000000..9383acb16d7e --- /dev/null +++ b/packages/guides/tailwind.config.mjs @@ -0,0 +1,18 @@ +import defaultTheme from 'tailwindcss/defaultTheme'; + +/** @type {import('tailwindcss').Config} */ +export default { + content: [ + './pages/**/*.{js,ts,jsx,tsx}', + './components/**/*.{js,ts,jsx,tsx}', + './app/**/*.{js,ts,jsx,tsx}', + ], + theme: { + extend: { + fontFamily: { + sans: ['Inter', ...defaultTheme.fontFamily.sans], + }, + }, + }, + plugins: [], +}; \ No newline at end of file diff --git a/packages/guides/tsconfig.json b/packages/guides/tsconfig.json new file mode 100644 index 000000000000..acde69463acb --- /dev/null +++ b/packages/guides/tsconfig.json @@ -0,0 +1,22 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "dist", + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "baseUrl": ".", + "paths": { + "@/*": [ + "*" + ] + }, + "resolveJsonModule": true, + "jsx": "preserve", + "module": "ESNext" + }, + "include": [ + "src" + ] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3109a1fa0ab3..55ebbe9f5309 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -51,6 +51,34 @@ importers: specifier: ^5.8.3 version: 5.8.3 + packages/guides: + dependencies: + fuse.js: + specifier: ^7.0.0 + version: 7.1.0 + next: + specifier: ^14.2.28 + version: 14.2.28(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + react: + specifier: ^18.3.1 + version: 18.3.1 + react-dom: + specifier: ^18.3.1 + version: 18.3.1(react@18.3.1) + devDependencies: + autoprefixer: + specifier: ^10.4.21 + version: 10.4.21(postcss@8.5.3) + postcss: + specifier: ^8.5.3 + version: 8.5.3 + tailwindcss: + specifier: ^3.4.17 + version: 3.4.17 + typescript: + specifier: ^5.8.3 + version: 5.8.3 + packages/og-image: dependencies: '@resvg/resvg-wasm': @@ -5322,6 +5350,10 @@ packages: functions-have-names@1.2.3: resolution: {integrity: sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==} + fuse.js@7.1.0: + resolution: {integrity: sha512-trLf4SzuuUxfusZADLINj+dE8clK1frKdmqiJNb1Es75fmI5oY6X2mxLVUciLLjxqw/xr72Dhy+lER6dGd02FQ==} + engines: {node: '>=10'} + get-caller-file@2.0.5: resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} engines: {node: 6.* || 8.* || >= 10.*} @@ -15435,6 +15467,8 @@ snapshots: functions-have-names@1.2.3: {} + fuse.js@7.1.0: {} + get-caller-file@2.0.5: {} get-intrinsic@1.3.0: @@ -17440,8 +17474,8 @@ snapshots: ox@0.6.9(typescript@5.8.3)(zod@3.24.3): dependencies: '@adraffy/ens-normalize': 1.11.0 - '@noble/curves': 1.8.2 - '@noble/hashes': 1.7.2 + '@noble/curves': 1.9.0 + '@noble/hashes': 1.8.0 '@scure/bip32': 1.6.2 '@scure/bip39': 1.5.4 abitype: 1.0.8(typescript@5.8.3)(zod@3.24.3)