-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not extract heading from content (#506)
* fix: do not extract heading from content * fix: update shortcuts * fix: remove anchor link from H1 tag * ✨ (extraction) update content and fix styling Co-authored-by: Yaël GUILLOUX <yael.guilloux@gmail.com>
- Loading branch information
Showing
26 changed files
with
136 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import defu from 'defu' | ||
import { expandTags, flatUnwrap, nodeTextContent } from '../../runtime/utils' | ||
import { DocusRootNode } from '../../../types' | ||
|
||
export function processHeading(body: DocusRootNode) { | ||
let title = '' | ||
let description = '' | ||
const children = body.children | ||
// top level `text` can be ignored | ||
.filter(node => node.type !== 'text') | ||
|
||
if (children.length && expandTags(['h1']).includes(children[0].tag)) { | ||
/** | ||
* Remove node | ||
*/ | ||
const node = children.shift() | ||
|
||
/** | ||
* Remove anchor link from H1 tag | ||
*/ | ||
node.children = flatUnwrap(node.children, ['a']) | ||
|
||
/** | ||
* Generate title | ||
*/ | ||
title = nodeTextContent(node) | ||
|
||
/** | ||
* Inject class | ||
*/ | ||
node.props = defu(node.props, { | ||
class: 'd-heading-title' | ||
}) | ||
} | ||
|
||
if (children.length && expandTags(['p']).includes(children[0].tag)) { | ||
/** | ||
* Remove node | ||
*/ | ||
const node = children.shift() | ||
|
||
/** | ||
* Generate description | ||
*/ | ||
description = nodeTextContent(node) | ||
|
||
/** | ||
* Inject class | ||
*/ | ||
node.props = defu(node.props, { | ||
class: 'd-heading-description' | ||
}) | ||
} | ||
|
||
if (children.length && expandTags(['hr']).includes(children[0].tag)) { | ||
/** | ||
* Remove node | ||
*/ | ||
const node = children.shift() | ||
|
||
/** | ||
* Inject class | ||
*/ | ||
node.props = defu(node.props, { | ||
class: 'd-heading-hr' | ||
}) | ||
} | ||
|
||
return { | ||
title, | ||
description, | ||
body | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
d508213
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nuxtjs-with-docus – ./
nuxtjs.docus.com
nuxtjs-with-docus-git-dev-nuxtlabs.vercel.app
nuxtjs-with-docus.vercel.app
nuxtjs-with-docus-nuxtlabs.vercel.app