Skip to content

Commit

Permalink
[v3] add icons for following languages: - GraphQL, C++, C#, Python (#…
Browse files Browse the repository at this point in the history
…2674)

* Showcase React Cosmos docs (#2647)

* Update theme-configuration.mdx (#2221)

* Update theme-configuration.mdx

Added the note about disabling the edit link.

* fix normalize pagemap

* a

---------

Co-authored-by: Dimitri POSTOLOV <[email protected]>

* chore(deps): update actions/cache action to v4 (#2642)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update pnpm to v8.15.1 (#2499)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update styfle/cancel-workflow-action action to v0.12.1 (#2670)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Version Packages (#2668)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* more

* aa

* prettier

* make tests pass

* prettier

* fix sort of html attributes when codeHighlight=false

---------

Co-authored-by: Ovidiu Cherecheș <[email protected]>
Co-authored-by: Kruno Golubic <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
6 people authored Feb 2, 2024
1 parent b6441ec commit 5a63701
Show file tree
Hide file tree
Showing 27 changed files with 287 additions and 57 deletions.
14 changes: 14 additions & 0 deletions .changeset/hot-geese-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'nextra-theme-blog': minor
'nextra-theme-docs': minor
'nextra': minor
---

add icons for following languages:

- GraphQL (`graphql`)
- C++ (`c++`, `cpp`)
- C# (`csharp`, `c#`, `cs`)
- Python (`python`, `py`)

allow disallow mobile word wrap button in code blocks with `word-wrap=false` meta data setting
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Cancel Previous Runs
uses: styfle/[email protected].0
uses: styfle/[email protected].1
with:
access_token: ${{ github.token }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nextjs-bundle-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected].0
uses: styfle/[email protected].1
with:
access_token: ${{ github.token }}

Expand All @@ -33,7 +33,7 @@ jobs:
run: pnpm i

- name: Restore Next.js Build
uses: actions/cache@v3
uses: actions/cache@v4
id: restore-build-cache
env:
cache-name: cache-next-build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

steps:
- name: Cancel Previous Runs
uses: styfle/[email protected].0
uses: styfle/[email protected].1
with:
access_token: ${{ github.token }}

Expand Down
13 changes: 10 additions & 3 deletions docs/pages/docs/docs-theme/theme-configuration.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Screenshot } from 'components/screenshot'
import { OptionTable } from 'components/table'
import { Callout } from 'nextra/components'
import sidebarTitleComponentImage from 'public/assets/docs/sidebar-customized.png'

# Theme Configuration
Expand All @@ -13,7 +14,7 @@ export default {
project: {
link: 'https://github.com/shuding/nextra'
},
logo: <strong>Project</strong>
logo: <b>Project</b>
}
```

Expand Down Expand Up @@ -561,12 +562,16 @@ Show an “Edit this page” link on the page that points to the file URL on Git
children: React.ReactNode
className?: string
filePath?: string
}>`,
}> | null`,
'Customized edit link component.'
]
]}
/>

<Callout type="info">
To disable it, you can set `editLink.component` to `null`.
</Callout>

### Feedback Link

The built-in feedback link provides a way for users to submit feedback about the
Expand Down Expand Up @@ -594,7 +599,9 @@ the docs repository, with the current website title prefilled:
]}
/>

To disable it, you can set `feedback.content` to `null`.
<Callout type="info">
To disable it, you can set `feedback.content` to `null`.
</Callout>

## End of Page

Expand Down
3 changes: 3 additions & 0 deletions docs/pages/showcase.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ source projects powered by Nextra</p>}
>
<>![JavaScript Code Challenges preview](./showcase/jscodechallenges.png)</>
</ShowcaseCard>
<ShowcaseCard title="React Cosmos" href="https://reactcosmos.org">
<>![React Cosmos preview](./showcase/react-cosmos.png)</>
</ShowcaseCard>
</Cards>

export const ShowcaseCard = Object.assign(
Expand Down
Binary file added docs/pages/showcase/react-cosmos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/swr-site/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
28 changes: 28 additions & 0 deletions examples/swr-site/pages/en/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@ import { Callout, FileTree } from 'nextra/components'

https://google.com/da;djaldhksagfugsufgasuyfgyuasgfuasgdjasbdjasdjkasfuydfasyrdyafsdygasjdgasgdsafgdhjfasgjdfsahjdfsahjgdasgdjkasgdkjasgdkjasgdkagdkjasgdkjagdkjagdkagdkagdkjagdkagdkagdkagda

```css filename="CSS" word-wrap=false
html {
background: red;
}
```

```graphql filename="GraphQL"
type Character {
name: String
}
```

```python filename="Python"
# type Character {
class Character:
# name: String
def name(self):
return self._name
```

```csharp filename="C#"
// type Character {
public class Character {
// name: String
public String Name { get; }
}
```

`__esModule`

`Docs theme box-decoration-theme: clone can create confusing output over line breaks`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"packageManager": "pnpm@8.9.2",
"packageManager": "pnpm@8.15.1",
"scripts": {
"build": "turbo run build:tailwind build --filter=./packages/\\*",
"build:all": "turbo run build:tailwind build",
Expand Down
7 changes: 7 additions & 0 deletions packages/nextra-theme-blog/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@
- Updated dependencies [576cb6f1]
- [email protected]

## 2.13.3

### Patch Changes

- Updated dependencies [93b57052]
- [email protected]

## 2.13.2

### Patch Changes
Expand Down
11 changes: 11 additions & 0 deletions packages/nextra-theme-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@
- Updated dependencies [576cb6f1]
- [email protected]

## 2.13.3

### Patch Changes

- 93b57052: allow to disable `editLink` by specifying `editLink.component: null`
in theme config
- 93b57052: fix `type: 'separator'` zod validation, mark `title` field as
optional
- Updated dependencies [93b57052]
- [email protected]

## 2.13.2

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/nextra-theme-docs/src/components/banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export function Banner(): ReactElement | null {
'nextra-banner-container max-md:_sticky _top-0 _z-20 _flex _items-center',
'_h-[var(--nextra-banner-height)] [body.nextra-banner-hidden_&]:_hidden',
'_text-slate-50 dark:_text-white _bg-neutral-900 dark:_bg-[linear-gradient(1deg,#383838,#212121)]',
'_px-2 ltr:_pl-10 rtl:_pr-10 print:_hidden'
'_px-2 _ps-10 print:_hidden'
)}
>
<div className="_w-full _truncate _px-4 _text-center _font-medium _text-sm">
<div className="_w-full _truncate _text-center _font-medium _text-sm">
{renderComponent(banner.content)}
</div>
{banner.dismissible && (
Expand Down
16 changes: 9 additions & 7 deletions packages/nextra-theme-docs/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ export const themeSchema = /* @__PURE__ */ (() =>
direction: z.enum(['ltr', 'rtl']),
docsRepositoryBase: z.string().startsWith('https://'),
editLink: z.strictObject({
component: z.custom<
FC<{
children: ReactNode
className?: string
filePath?: string
}>
>(...fc),
component: z
.custom<
FC<{
children: ReactNode
className?: string
filePath?: string
}>
>(...fc)
.or(z.null()),
content: z.custom<ReactNode | FC>(...reactNode)
}),
faviconGlyph: z.string().optional(),
Expand Down
7 changes: 7 additions & 0 deletions packages/nextra/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@

- d8a406b4: add `"sideEffects": false` for better tree-shaking

## 2.13.3

### Patch Changes

- 93b57052: fix `type: 'separator'` zod validation, mark `title` field as
optional

## 2.13.2

### Patch Changes
Expand Down
12 changes: 7 additions & 5 deletions packages/nextra/__test__/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ describe('Code block', () => {
mdxOptions
})
expect(result).toMatch(
'<_components.pre data-language="text" data-filename="test.js">'
'<_components.pre data-language="text" data-word-wrap="" data-filename="test.js">'
)
})

Expand All @@ -482,7 +482,9 @@ describe('Code block', () => {
mdxOptions,
codeHighlight: false
})
expect(result).toMatch('<_components.pre data-filename="test.js">')
expect(result).toMatch(
'<_components.pre data-filename="test.js" data-word-wrap="">'
)
})

it('not highlight filename as substring', async () => {
Expand Down Expand Up @@ -515,7 +517,7 @@ describe('Code block', () => {
mdxOptions,
codeHighlight
})
expect(result).toMatch('data-copy="">')
expect(result).toMatch('data-word-wrap="" data-copy="">')
})

it('attach with "defaultShowCopyCode: true"', async () => {
Expand All @@ -524,7 +526,7 @@ describe('Code block', () => {
defaultShowCopyCode: true,
codeHighlight
})
expect(result).toMatch('data-copy="">')
expect(result).toMatch('data-word-wrap="" data-copy="">')
})

it('not attach with "defaultShowCopyCode: true" and "copy=false"', async () => {
Expand All @@ -533,7 +535,7 @@ describe('Code block', () => {
defaultShowCopyCode: true,
codeHighlight
})
expect(result).not.toMatch('data-copy="">')
expect(result).not.toMatch('data-copy=""')
})
})
}
Expand Down
40 changes: 22 additions & 18 deletions packages/nextra/src/client/components/pre.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
import cn from 'clsx'
import type { ComponentProps, FC, ReactElement } from 'react'
import { useCallback, useRef } from 'react'
import { useRef } from 'react'
import { WordWrapIcon } from '../icons/index.js'
import { Button, classes } from './button.js'
import { CopyToClipboard } from './copy-to-clipboard.js'

function toggleWordWrap() {
const htmlDataset = document.documentElement.dataset
const hasWordWrap = 'nextraWordWrap' in htmlDataset
if (hasWordWrap) {
delete htmlDataset.nextraWordWrap
} else {
htmlDataset.nextraWordWrap = ''
}
}

export function Pre({
children,
className,
'data-filename': filename,
'data-copy': copy,
'data-language': _language,
'data-word-wrap': hasWordWrap,
icon: Icon,
...props
}: ComponentProps<'pre'> & {
'data-filename'?: string
'data-copy'?: ''
'data-language'?: string
'data-word-wrap'?: ''
icon?: FC<ComponentProps<'svg'>>
}): ReactElement {
const preRef = useRef<HTMLPreElement | null>(null)

const toggleWordWrap = useCallback(() => {
const htmlDataset = document.documentElement.dataset
const hasWordWrap = 'nextraWordWrap' in htmlDataset
if (hasWordWrap) {
delete htmlDataset.nextraWordWrap
} else {
htmlDataset.nextraWordWrap = ''
}
}, [])

const copyButton = copy === '' && (
<CopyToClipboard
className={filename ? '_ml-auto' : ''}
Expand Down Expand Up @@ -77,13 +79,15 @@ export function Pre({
filename ? '_top-14' : '_top-2'
)}
>
<Button
onClick={toggleWordWrap}
className="md:_hidden"
title="Toggle word wrap"
>
<WordWrapIcon className="_h-4 _w-auto" />
</Button>
{hasWordWrap === '' && (
<Button
onClick={toggleWordWrap}
className="md:_hidden"
title="Toggle word wrap"
>
<WordWrapIcon className="_h-4 _w-auto" />
</Button>
)}
{!filename && copyButton}
</div>
</div>
Expand Down
13 changes: 13 additions & 0 deletions packages/nextra/src/client/icons/c++.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions packages/nextra/src/client/icons/csharp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions packages/nextra/src/client/icons/css.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5a63701

Please sign in to comment.