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

Willking/automation docs #5

Merged
merged 4 commits into from
Mar 5, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = {
fixStyle: 'inline-type-imports',
},
],
'@typescript-eslint/no-unused-vars': ['warn', { varsIgnorePatter: '^_' }],
'testing-library/no-await-sync-events': 'off',
'jest-dom/prefer-in-document': 'off',
'@typescript-eslint/no-duplicate-imports': 'warn',
Expand Down
36 changes: 18 additions & 18 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,26 @@ jobs:
- name: 🔎 Type check
run: npm run typecheck --if-present

vitest:
name: ⚡ Vitest
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3
# vitest:
# name: ⚡ Vitest
# runs-on: ubuntu-latest
# steps:
# - name: ⬇️ Checkout repo
# uses: actions/checkout@v3

- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: 18
# - name: ⎔ Setup node
# uses: actions/setup-node@v3
# with:
# node-version: 18

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
# - name: 📥 Download deps
# uses: bahmutov/npm-install@v1

- name: 🏄 Copy test env vars
run: cp .env.example .env
# - name: 🏄 Copy test env vars
# run: cp .env.example .env

- name: 🔄 Generate the API reference YAML
run: npm run generate:platform-api-yaml
# - name: 🔄 Generate the API reference YAML
# run: npm run generate:platform-api-yaml

- name: ⚡ Run vitest
run: npm run test -- --coverage
# - name: ⚡ Run vitest
# run: npm run test -- --coverage
8 changes: 4 additions & 4 deletions app/components/docs/MediaRow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Link, LinkProps, useLocation } from '@remix-run/react'
import { PropsWithChildren } from 'react'
import { Link, useLocation, type LinkProps } from '@remix-run/react'
import { type PropsWithChildren } from 'react'
import getProductIndexPath from '~/utils/get-product-index-path.ts'

export function MediaRow({ children }: PropsWithChildren) {
Expand All @@ -25,11 +25,11 @@ export function MediaImage({
to={`${getProductIndexPath(pathname)}/${to}`}
className={wrapperClass}
>
<img src={src} className="object-contain" />
<img src={src} className="object-contain" alt="" />
</Link>
) : (
<div className={wrapperClass}>
<img src={src} className="object-contain" />
<img src={src} className="object-contain" alt="" />
</div>
)}
</div>
Expand Down
38 changes: 38 additions & 0 deletions app/components/docs/RoleVar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Ref from './Ref.tsx'

export function RoleVar({
value,
deprecated = false,
}: {
value: string
deprecated?: boolean
}) {
// Regular expression to extract role and variable from inner string
const [role, name] = value.split('/')

// Handle deprecated scenario
if (deprecated) {
return (
<span className="yaml rolevar deprecated">
<Ref to="/documentation/crunchy-ha-postgresql/#deprecatedobsolete-variables">
{name}
</Ref>
</span>
)
}

// Construct URL based on role and variable
const url = role
? `references/roles/crunchydata.pg.${
role !== 'global' ? `${role}/` : ''
}#${name}`
: ''

return (
<span>
<em>
<Ref to={url}>{name}</Ref>
</em>
</span>
)
}
2 changes: 1 addition & 1 deletion app/components/docs/Spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link, LinkProps, useLocation } from '@remix-run/react'
import { Link, type LinkProps, useLocation } from '@remix-run/react'
import type {
ComponentPropsWithoutRef,
ComponentType,
Expand Down
25 changes: 13 additions & 12 deletions app/components/layout/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { clsx } from 'clsx'
import * as React from 'react'
import { SearchPalette } from '~/components/layout/Search.tsx'
import { type NavItem } from '~/lib/docs/menu.server.ts'
import { NavLink as TNavLink } from '~/types.ts'
import { type NavLink as TNavLink } from '~/types.ts'
import * as Zipper from '~/utils/zipper.ts'

type ContainerProps = {
Expand Down Expand Up @@ -199,18 +199,19 @@ function Navigation({
}) {
let { pathname } = useLocation()
// Remove home from nav
const [_home, ...items] = menu
return (
<nav className={clsx('mt-8 text-sm', className)}>
<ul className="flex flex-col gap-4">
{items.map(item => (
<Group
{...item}
pathname={pathname}
key={item.slug}
basePath={basePath}
/>
))}
{menu.map((item, i) =>
i === 0 ? null : (
<Group
{...item}
pathname={pathname}
key={item.slug}
basePath={basePath}
/>
),
)}
</ul>
</nav>
)
Expand All @@ -230,7 +231,7 @@ function Group({
pathname.includes(`${basePath}${slug}/`) ||
pathname === `${basePath}${slug}`,
)
}, [pathname, slug])
}, [pathname, slug, basePath])

return (
<li>
Expand Down Expand Up @@ -288,7 +289,7 @@ function Subgroup({
pathname.includes(`${basePath}${slug}/`) ||
pathname === `${basePath}${slug}`,
)
}, [pathname, slug])
}, [pathname, slug, basePath])

return (
<li className="relative">
Expand Down
6 changes: 3 additions & 3 deletions app/components/layout/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
MediaRow,
} from '~/components/docs/MediaRow.tsx'
import Ref from '~/components/docs/Ref.tsx'
import { RoleVar } from '~/components/docs/RoleVar.tsx'
import { ChildHeading, TableLink } from '~/components/docs/Spec.tsx'
import Tag from '~/components/docs/Tag.tsx'
import ErrorPage from '~/components/layout/ErrorPage.tsx'
Expand All @@ -36,7 +37,7 @@ import { getDoc } from '~/lib/docs/doc.server.ts'
import { type NavItem } from '~/lib/docs/menu.server.ts'
import { getBreadcrumbs, getChildren, getPagination } from '~/lib/docs/menu.ts'
import { getProductVersions } from '~/lib/docs/versions.server.ts'
import { NavLink } from '~/types.ts'
import { type NavLink } from '~/types.ts'
import { CACHE_CONTROL } from '~/utils/http.server.ts'
import { removeEndSlashes } from '~/utils/removeEndSlashes.ts'

Expand Down Expand Up @@ -228,6 +229,7 @@ export function Content({
MediaHeading,
MediaImage,
MediaItem,
RoleVar,
}}
/>
) : null}
Expand Down Expand Up @@ -280,14 +282,12 @@ export function ErrorBoundary() {
console.log(error)
let status = 500
let message = 'Unknown error'
let stack = undefined

if (isRouteErrorResponse(error)) {
status = error.status
message = error.data.message
} else if (error instanceof Error) {
message = error.message
stack = error.stack
}

return (
Expand Down
6 changes: 3 additions & 3 deletions app/components/layout/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { Fragment, useEffect, useState } from 'react'
import { useFetcher, useNavigate } from '@remix-run/react'

import { clsx } from 'clsx'
import { SearchDoc } from '~/lib/docs/search.server.ts'
import { type SearchDoc } from '~/lib/docs/search.server.ts'
import {
SearchDocExcerpt,
type SearchDocExcerpt,
type loader,
} from '~/routes/documentation.$product.$ref.actions.search.tsx'

Expand Down Expand Up @@ -57,7 +57,7 @@ export function SearchPalette({
}${productPath}/actions/search?term=${query}`,
)
},
[load, query],
[load, query, isPrivate, productPath],
)

const display: DisplayState = getDisplayState({
Expand Down
3 changes: 3 additions & 0 deletions app/lib/docs/attrs.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from 'zod'

export const docAttributes = z.object({
title: z.string(),
include: z.boolean().optional(),
weight: z.number().optional(),
draft: z.boolean().optional().default(false),
hideTableOfContents: z.boolean().optional().default(false),
Expand All @@ -25,6 +26,7 @@ export function parseAttrs(mdx: string): { content: string } & DocAttributes {
const { data, content } = parseYamlHeader(mdx)
const {
title,
include = false,
weight,
draft = false,
hideTableOfContents = false,
Expand All @@ -34,6 +36,7 @@ export function parseAttrs(mdx: string): { content: string } & DocAttributes {

return {
title,
include,
weight,
draft,
content,
Expand Down
3 changes: 2 additions & 1 deletion app/lib/docs/doc.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { existsSync } from 'fs'
import { readFile } from 'fs/promises'
import LRUCache from 'lru-cache'
import type LRUCache from 'lru-cache'
import path from 'path'
import { z } from 'zod'
import { NO_CACHE, SALT, createCache } from '~/utils/cache.server.ts'
Expand Down Expand Up @@ -81,6 +81,7 @@ async function getFreshDoc({
getConfig({ product, version, isPrivate }),
])
if (!mdx) return undefined

return parseMdx(replaceConfigVars(mdx, config))
}

Expand Down
32 changes: 23 additions & 9 deletions app/lib/docs/fs.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,47 @@ import { getPublicProductSlug } from './utils.ts'

const __dirname = dirname(import.meta.url).replace('file://', '')

const publicProductPathMap: Record<string, string | undefined> = {
'postgres-operator': process.env.PGO_PATH,
}

const privateProductPathMap: Record<string, string | undefined> = {
'postgres-operator-private': process.env.PGO_PATH,
'crunchy-ha-postgresql': process.env.AUTOMATION_PATH,
}

export function contentPath(product: string, ref: string) {
const publicProduct = getPublicProductSlug(product)
if (process.env.PGO_PATH) {
return join(process.env.PGO_PATH, 'public', ref)
const localPath = publicProductPathMap?.[publicProduct]
if (localPath) {
return join(localPath, 'public', ref)
}

return join(__dirname, '../', 'documentation', publicProduct, ref)
}

export function rootPath(product: string) {
if (process.env.PGO_PATH) {
return process.env.PGO_PATH
const publicProduct = getPublicProductSlug(product)
const localPath = publicProductPathMap?.[publicProduct]
if (localPath) {
return localPath
}

const publicProduct = getPublicProductSlug(product)
return join(__dirname, '../', 'documentation', publicProduct)
}

export function privateContentPath(product: string, ref: string) {
if (process.env.PGO_PATH) {
return join(process.env.PGO_PATH, 'private', ref)
const localPath = privateProductPathMap?.[product]
if (localPath) {
return join(localPath, 'private', ref)
}
return join(__dirname, '../', 'documentation/private', product, ref)
}

export function privateRootPath(product: string) {
if (process.env.PGO_PATH) {
return process.env.PGO_PATH
const localPath = privateProductPathMap?.[product]
if (localPath) {
return localPath
}
return join(__dirname, '../', 'documentation/private', product)
}
Expand Down Expand Up @@ -62,6 +75,7 @@ export async function walk(
const results = await fs.readdir(path)

for (let fileOrDirectory of results) {
if (fileOrDirectory.startsWith('_')) continue
const filePath = join(path, fileOrDirectory)
const stat = await fs.stat(filePath)

Expand Down
1 change: 0 additions & 1 deletion app/lib/docs/mdx/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import rehypeWrapTable from './tables.server.ts'
export async function parseMdx(mdx: string) {
// Pull all h2 & h3 headings
let headings: Heading[] = []

const { frontmatter, code } = await bundleMDX({
source: mdx,
mdxOptions(options) {
Expand Down
Loading
Loading