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

Move Documentation components to theme #3170

Merged
merged 35 commits into from
Jan 31, 2022
Merged

Conversation

rogermparent
Copy link
Contributor

This PR is a bottom-up moving of the Documentation component, and any components it depends on (and there's a lot) to the gatsby-theme-iterative-docs plugin.

@rogermparent rogermparent changed the title Add components to plugin Move Documentation components to theme Jan 10, 2022
@shcheklein shcheklein temporarily deployed to dvc-org-add-components--hurhqb January 10, 2022 23:00 Inactive
@rogermparent rogermparent temporarily deployed to dvc-org-add-components--eykf0l January 10, 2022 23:00 Inactive
@shcheklein shcheklein temporarily deployed to dvc-org-add-components--98uvhr January 10, 2022 23:05 Inactive
@rogermparent rogermparent temporarily deployed to dvc-org-add-components--98uvhr January 10, 2022 23:42 Inactive
@rogermparent rogermparent temporarily deployed to dvc-org-add-components--98uvhr January 11, 2022 02:20 Inactive
@rogermparent rogermparent temporarily deployed to dvc-org-add-components--98uvhr January 14, 2022 19:44 Inactive
const { getItemByPath } = require('../../src/utils/shared/sidebar')
const {
getItemByPath
} = require('../../plugins/gatsby-theme-iterative-docs/src/utils/shared/sidebar')
Copy link
Contributor Author

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.

Comment on lines +1 to +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
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reimplemented #3143

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any website where we don't use remark plugins?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Comment on lines +37 to +54
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'
)
}
}
})
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 gatsby-node and other pure node modules to work with the same imports, and so allowing the modules that import these to be used in both environments, enabling the utils/shared modules to work even in an external module.

Comment on lines +8 to +13
export interface IPaginatorPageInfo {
currentPage: number
nextPage?: string
previousPage?: string
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this interface but not the rest of Paginator

@@ -2,7 +2,7 @@ import React from 'react'

import MainLayout from '../MainLayout'
import DefaultSEO from './DefaultSEO'
import DocumentationLayout from '../Documentation/Layout'
import DocumentationLayout from '../DocumentationLayout'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We took the rest of the Documentation component but left Documentation/Layout behind and promoted it to its own standalone component.
Taking this into the theme would mean a lot more components the layout depends on would have to be pulled in, but this layout actually isn't very closely coupled with the rest of the Documentation component so breaking it apart works nicely.

Comment on lines +22 to +26
"paths": {
"gatsby-theme-iterative-docs/*": [
"./plugins/gatsby-theme-iterative-docs/*"
]
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enables tsc linting to work with the faked package imports, and will have to be removed once the theme becomes a real package.

@rogermparent rogermparent temporarily deployed to dvc-org-add-components--98uvhr January 25, 2022 21:10 Inactive
@rogermparent rogermparent temporarily deployed to dvc-org-add-components--98uvhr January 25, 2022 21:57 Inactive
@rogermparent rogermparent temporarily deployed to dvc-org-add-components--98uvhr January 25, 2022 23:21 Inactive
Comment on lines +1 to +23
import React from 'react'

import MainLayout, { LayoutComponent, LayoutModifiers } from '../MainLayout'
import ThemeDocumentationLayout from 'gatsby-theme-iterative-docs/src/components/Documentation/Layout'

const Layout: LayoutComponent = ({ children, ...restProps }) => {
const {
location: { pathname }
} = restProps

return (
<MainLayout
{...restProps}
modifiers={[LayoutModifiers.Wide, LayoutModifiers.Collapsed]}
>
<ThemeDocumentationLayout currentPath={pathname}>
{children}
</ThemeDocumentationLayout>
</MainLayout>
)
}

export default Layout
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the latest iteration, I noticed the inner part of DocumentationLayout is pretty necessary to make the whole thing work, but thankfully only MainLayout pulls in a bunch of website dependencies so it can be easily broken off here.

@rogermparent rogermparent marked this pull request as ready for review January 26, 2022 01:51
Copy link
Contributor

@julieg18 julieg18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and everything seems to be working correctly!

@rogermparent
Copy link
Contributor Author

Looks good and everything seems to be working correctly!

Here's hoping it stays that way on merge!

@jorgeorpinel jorgeorpinel added the website: eng-doc DEPRECATED JS engine for /doc label Jan 27, 2022
Copy link
Contributor

@yathomasi yathomasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good on my end too.

@rogermparent rogermparent had a problem deploying to dvc-org-add-components--98uvhr January 31, 2022 20:29 Failure
@rogermparent rogermparent temporarily deployed to dvc-org-add-components--98uvhr January 31, 2022 20:41 Inactive
@rogermparent rogermparent temporarily deployed to dvc-org-add-components--98uvhr January 31, 2022 21:40 Inactive
@rogermparent rogermparent temporarily deployed to dvc-org-add-components--98uvhr January 31, 2022 21:55 Inactive
@rogermparent
Copy link
Contributor Author

rogermparent commented Jan 31, 2022

There was one build where images were broken in docs, but it seemed to clear up after a cache clear. I'll try another cached build and see if it happens again, otherwise I'll merge.

Looks like it was fixed! I'll keep an eye on master just in case.

@rogermparent rogermparent merged commit 75d8197 into master Jan 31, 2022
@rogermparent rogermparent deleted the add-components-to-plugin branch January 31, 2022 22:02
iesahin pushed a commit that referenced this pull request Apr 11, 2022
* Move sidebar logic to theme

* Split sidebar normalization and utils and import via shadowing

* Fix usage of findChildWithSource

* Fix lint-ts errors

* Move comment normalized item definition to d.ts

* Update and export INormalizedSidebarItem and use it in SidebarMenu

* Add suppressable default gatsby-transformer-remark definition

* Remove resolve-sidebar since local remark plugins are dvc.org only

* Remove resolve-sidebar since local remark plugins are dvc.org only

* Return src/components to master

* Add alias for local theme

* Roughly move doc components to theme

* Revert to master package.json

* Remove unused normalize sidebar module

* Re-fix package.json and change test imports

* stylelint --fix

* Move Page and DocumentationLayout from theme to site

* Fix svg imports

* Remove unused layout components

* stylelint fix

* Extract github link function and repo constant to more easily overridable files

* Remove unnecessary shadowed files since webpack override is in place

* Remove unused constants file

* Revert "Remove unused constants file"

This reverts commit b07ca1b.

* Remove actual unused constants file

* Use theme-based Link component

* Move core part of Documentation layout into theme

* Rename sidebar test block to something more descriptive of its contents

* Break apart docs sidebar and move it into theme

* Add missing import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
website: eng-doc DEPRECATED JS engine for /doc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants