-
Notifications
You must be signed in to change notification settings - Fork 394
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
Move Documentation components to theme #3170
Changes from 29 commits
8b92ebe
b73d69a
0f1c0fe
332644a
c127d19
a24e1d6
e626bd0
b077fbb
978b27b
a6cfd96
b771dc0
8df9091
57d4743
c2b0462
ba8bda3
912e5fe
c311791
56d1ae3
e823d91
a9027a0
6c11d10
456c1c5
fad07b2
9407736
d4b0985
df3bc68
b07ca1b
18ae55f
857351b
0703ac9
a8b4b1a
f2e61e6
d975f02
88ed746
daad2be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module.exports = ({ remark }) => { | ||
const plugins = [] | ||
if (remark) { | ||
plugins.push({ | ||
resolve: 'gatsby-transformer-remark', | ||
options: { | ||
plugins: [ | ||
'gatsby-remark-embedder', | ||
{ | ||
resolve: 'gatsby-remark-prismjs', | ||
options: { | ||
noInlineHighlight: true, | ||
languageExtensions: [ | ||
{ | ||
language: 'text', | ||
definition: {} | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
resolve: 'gatsby-remark-smartypants', | ||
options: { | ||
quotes: false | ||
} | ||
}, | ||
{ | ||
resolve: 'gatsby-remark-embed-gist', | ||
options: { | ||
includeDefaultCss: true | ||
} | ||
}, | ||
'gatsby-remark-relative-images', | ||
'gatsby-remark-copy-linked-files', | ||
'gatsby-remark-external-links', | ||
{ | ||
resolve: 'gatsby-remark-autolink-headers', | ||
options: { | ||
enableCustomId: true, | ||
isIconAfterHeader: true | ||
} | ||
}, | ||
{ | ||
resolve: 'gatsby-remark-images', | ||
options: { | ||
withWebp: true | ||
} | ||
}, | ||
'gatsby-remark-responsive-iframe' | ||
] | ||
} | ||
}) | ||
} | ||
return { | ||
plugins | ||
} | ||
} | ||
Comment on lines
+1
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reimplemented #3143 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any website where we don't use remark plugins? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iterative.ai doesn't, and likely won't, but it also wouldn't be using this theme. Also, cml.dev doesn't use the custom local remark plugins that dvc.org does, though it'll probably want to in the future. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,9 @@ exports.pluginOptionsSchema = ({ Joi }) => { | |
disable: Joi.boolean().default(Boolean(process.env.SKIP_DOCS)), | ||
getTemplate: Joi.function().default(() => defaultGetTemplate), | ||
defaultTemplate: Joi.string().default( | ||
path.resolve('src', 'templates', 'doc.tsx') | ||
) | ||
require.resolve('./src/templates/doc.tsx') | ||
), | ||
remark: Joi.boolean().default(true) | ||
}) | ||
} | ||
|
||
|
@@ -33,6 +34,25 @@ exports.createSchemaCustomization = async api => { | |
]) | ||
} | ||
|
||
exports.onCreateWebpackConfig = ({ actions }) => { | ||
actions.setWebpackConfig({ | ||
resolve: { | ||
alias: { | ||
[path.resolve(__dirname, 'sidebar')]: path.resolve( | ||
'src', | ||
'gatsby-theme-iterative-docs', | ||
'sidebar' | ||
), | ||
[path.resolve(__dirname, 'redirects')]: path.resolve( | ||
'src', | ||
'gatsby-theme-iterative-docs', | ||
'redirects' | ||
) | ||
} | ||
} | ||
}) | ||
} | ||
Comment on lines
+37
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The meat and potatoes to getting sidebar resolution working: this is similar to theme shadowing within Gatsby and uses the same directory structure on the consumer end, but the actual node files in the same location allow |
||
|
||
exports.createPages = require('./createPages.js') | ||
|
||
exports.onCreateNode = require('./onCreateNode.js') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// noop |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const path = require('path') | ||
const pseudoShadow = modulePath => require(path.resolve(modulePath)) | ||
module.exports = pseudoShadow |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const pseudoShadow = require('./pseudo-shadow') | ||
module.exports = pseudoShadow('./src/gatsby-theme-iterative-docs/redirects') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const pseudoShadow = require('./pseudo-shadow') | ||
module.exports = pseudoShadow('./src/gatsby-theme-iterative-docs/sidebar') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import React, { useCallback } from 'react' | ||
import { URL } from 'iso-url' | ||
import { useLocation } from '@reach/router' | ||
import GatsbyLink from 'gatsby-link' | ||
import { getRedirect } from '../../utils/shared/redirects' | ||
import { scrollIntoLayout, getScrollNode } from '../../utils/front/scroll' | ||
import safeQuerySelector from '../../utils/front/safeQuerySelector' | ||
|
||
export type ILinkProps = { | ||
children: React.ReactNode | ||
className?: string | ||
href: string | ||
target?: undefined | '_blank' | ||
state?: unknown | ||
scrollOptions?: Record<string, unknown> | ||
optOutPreRedirect?: undefined | true | ||
} & React.AnchorHTMLAttributes<HTMLAnchorElement> | ||
|
||
const PROTOCOL_REGEXP = /^https?:\/\// | ||
const isRelative = (url: string): boolean => !PROTOCOL_REGEXP.test(url) | ||
const isMailto = (url: string): boolean => url.startsWith('mailto:') | ||
|
||
const ResultLinkComponent: React.FC<ILinkProps> = ({ | ||
href, | ||
children, | ||
rel, | ||
target, | ||
download = false, | ||
...restProps | ||
}) => { | ||
// Handle all situations where a basic `a` must be used over Gatsby Link | ||
const hrefIsRelative = isRelative(href) | ||
const hrefIsMailto = isMailto(href) | ||
const hrefHasTarget = typeof target === 'string' | ||
// Fragments within the page should be `a`, but links to other pages | ||
// that have anchors should be okay. | ||
const hrefIsRelativeFragment = href.startsWith('#') | ||
|
||
if ( | ||
download || | ||
!hrefIsRelative || | ||
hrefIsMailto || | ||
hrefHasTarget || | ||
hrefIsRelativeFragment | ||
) { | ||
/* | ||
Change external links without an explicit rel to have 'noopener | ||
noreferrer', but leave explicitly defined rels alone. | ||
Do the same with `target=_blank` | ||
*/ | ||
if (!hrefIsRelative) { | ||
if (typeof rel !== 'string') { | ||
rel = 'noopener noreferrer' | ||
} | ||
if (!hrefHasTarget) { | ||
target = '_blank' | ||
} | ||
} | ||
|
||
return ( | ||
<a | ||
download={download} | ||
href={href} | ||
rel={rel} | ||
target={target} | ||
{...restProps} | ||
> | ||
{children} | ||
</a> | ||
) | ||
} | ||
|
||
return ( | ||
<GatsbyLink to={href} {...restProps}> | ||
{children} | ||
</GatsbyLink> | ||
) | ||
} | ||
|
||
const scrollToHash = (hash: string, scrollOptions = {}): void => { | ||
if (hash) { | ||
scrollIntoLayout(safeQuerySelector(hash), { | ||
waitImages: true, | ||
...scrollOptions | ||
}) | ||
} | ||
} | ||
|
||
const Link: React.FC<ILinkProps> = ({ | ||
href, | ||
scrollOptions, | ||
optOutPreRedirect, | ||
...restProps | ||
}) => { | ||
const currentLocation = useLocation() | ||
|
||
const onClick = useCallback( | ||
(e: React.MouseEvent<HTMLAnchorElement>) => { | ||
if (restProps.onClick) { | ||
restProps.onClick(e) | ||
} | ||
|
||
// Handle local fragments manually, allowing for more control than | ||
// native HTML fragment navigation. | ||
if (href === '#') { | ||
getScrollNode().scrollTop = 0 | ||
} else if (href.startsWith('#')) { | ||
e.preventDefault() | ||
|
||
// We can't navigate by direct usage of @reach/router#navigate because | ||
// gatsby-react-router-scroll will package intercept scroll in this | ||
// case and we will see undesired jump | ||
window.history.pushState(null, '', href) | ||
scrollToHash(href, scrollOptions) | ||
} | ||
}, | ||
[restProps.onClick, currentLocation] | ||
) | ||
|
||
const location = new URL(href) | ||
|
||
if (location.host === currentLocation.host && !optOutPreRedirect) { | ||
// Replace link href with redirect if it exists | ||
const [, redirectUrl] = getRedirect(location.host, location.pathname) | ||
|
||
if (redirectUrl) { | ||
href = isRelative(redirectUrl) | ||
? redirectUrl + currentLocation.search | ||
: redirectUrl | ||
} | ||
} | ||
|
||
return <ResultLinkComponent href={href} {...restProps} onClick={onClick} /> | ||
} | ||
|
||
export default Link |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,14 @@ import Helmet from 'react-helmet' | |
import { IGatsbyImageData } from 'gatsby-plugin-image' | ||
|
||
import getSiteMeta from '../../queries/siteMeta' | ||
import { IPaginatorPageInfo } from '../Paginator' | ||
import { buildMetadata, MetaProps } from './helper' | ||
|
||
export interface IPaginatorPageInfo { | ||
currentPage: number | ||
nextPage?: string | ||
previousPage?: string | ||
} | ||
|
||
Comment on lines
+8
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need this interface but not the rest of |
||
interface ISEOProps { | ||
title?: string | ||
defaultMetaTitle?: boolean | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const screens = { | ||
giant: 1200, | ||
desktop: 1005, | ||
tablet: 768, | ||
phablet: 572, | ||
phone: 376 | ||
} | ||
|
||
module.exports = { | ||
screens, | ||
customMedia: { | ||
'--xxs-scr': `(max-width: ${screens.phone}px)`, | ||
'--xs-scr': `(max-width: ${screens.phablet}px)`, | ||
'--sm-scr': `(max-width: ${screens.tablet}px)`, | ||
'--md-scr': `(max-width: ${screens.desktop - 1}px)`, | ||
'--lg-scr': `(min-width: ${screens.desktop}px)`, | ||
'--xl-scr': `(min-width: ${screens.giant}px)` | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const githubRepo = 'iterative/dvc' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { githubRepo } from './constants' | ||
export const getGithubLink = (sourcePath: string): string => | ||
`https://github.com/${githubRepo}/blob/master/content${sourcePath}` |
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.
Since these aren't webpacked, the imports will have to stay relative until the theme is a real package, which is the next step.