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

Add templates to doc pages and give docs home one #1268

Merged
merged 18 commits into from
May 22, 2020
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
40 changes: 27 additions & 13 deletions content/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,33 @@ Welcome! In here you may find all the guiding material and technical documents
needed to learn about DVC: how to use it, how it works, and where to go for
additional resources.

## Before you start
<cards>

<card href="/doc/tutorials/get-started" heading="Get Started">

A step-by-step introduction into basic DVC features

</card>

<card href="/doc/user-guide" heading="User Guide">

Study the detailed inner-workings of DVC in its user guide
Copy link
Contributor

Choose a reason for hiding this comment

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

Super minimal: Missing period. I'll add it no worries. Same in cmd ref card text


</card>

<card href="/doc/use-cases" heading="Use Cases">

Non-exhaustive list of scenarios DVC can help with

</card>

<card href="/doc/command-reference" heading="Command Reference">

See all of DVC's commands

</card>

</cards>

✅ Please join our [community](/community) or use the [support](/support)
channels if you have any questions or need specific help. We are very responsive
Expand All @@ -15,15 +41,3 @@ us a ⭐ if you like the project!

✅ Contribute to DVC [on GitHub](https://github.com/iterative/dvc) or help us
improve this [documentation](https://github.com/iterative/dvc.org) 🙏.

## Main topics

- Learn how to [install](/doc/install) and
[get started](/doc/tutorials/get-started) with DVC in the first sections.
- Explore the main [reasons](/doc/use-cases) to adopt DVC.
- Study the detailed [inner-workings](/doc/user-guide) of DVC, as well as each
one of its [commands](/doc/command-reference) and Python
[functions](/doc/api-reference).

Please choose a topic from the sidebar to the left, or click the `Next` button
below to start from the beginning ↘
57 changes: 56 additions & 1 deletion src/components/Documentation/Markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,66 @@ const Abbr: React.FC<{ children: [string] }> = ({ children }) => {
return <Tooltip text={children[0]} />
}

const Cards: React.FC = ({ children }) => {
return <div className={styles.cards}>{children}</div>
}

const InnerCard: React.FC<{
href?: string
className?: string
}> = ({ href, children, className }) =>
href ? (
<Link href={href} className={className}>
{children}
</Link>
) : (
<div className={className}>{children}</div>
)

const Card: React.FC<{
icon?: string
heading?: string
href?: string
headingtag:
| string
| React.FC<{
className: string
}>
}> = ({ children, icon, heading, headingtag: Heading = 'h3', href }) => {
let iconElement

if (Array.isArray(children) && icon) {
const firstRealItemIndex = children.findIndex(x => x !== '\n')
iconElement = children[firstRealItemIndex]
children = children.slice(firstRealItemIndex + 1)
}

return (
<div className={styles.cardWrapper}>
<InnerCard href={href} className={styles.card}>
{iconElement && <div className={styles.cardIcon}>{iconElement}</div>}
<div className={styles.cardContent}>
{heading && (
<Heading className={styles.cardHeading}>{heading}</Heading>
)}
{children}
</div>
</InnerCard>
</div>
)
}

const renderAst = new rehypeReact({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
createElement: React.createElement as any,
Fragment: React.Fragment,
components: { details: Details, abbr: Abbr, a: Link }
components: {
shcheklein marked this conversation as resolved.
Show resolved Hide resolved
details: Details,
abbr: Abbr,
a: Link,
card: Card,
cards: Cards
}
}).Compiler

interface IMarkdownProps {
Expand Down
78 changes: 78 additions & 0 deletions src/components/Documentation/Markdown/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,81 @@
margin-top: 2px;
}
}

.cards {
display: flex;
flex-flow: column nowrap;
margin: 1rem 0;

& > div {
padding: 0.5rem 0.1rem;
}

@media screen and (min-width: 1024px) {
margin: 2rem -0.5rem;
flex-flow: row wrap;

.cardWrapper {
flex: 1 0 50%;
padding: 0.5rem;
min-height: 7rem;
}

.card {
height: 100%;
}
}
}

.card {
border: 1px solid gray;
border-radius: 10px;
padding: 0.75rem 1rem;
display: flex;
width: 100%;
height: 100%;
flex-flow: row nowrap;
align-items: center;
box-sizing: border-box;

p {
margin: 0;
}

.cardIcon {
box-sizing: border-box;
display: block;
padding: 0;
padding-right: 0.75rem;
flex: 0 0 75px;

* {
margin: 0;
padding: 0;
display: block;
}
}

.cardHeading {
margin: 0;
margin-bottom: 0.25em;
font-weight: bold;
color: var(--color-gray-dark);
}

.cardContent {
flex: 1;
}
}

a.card {
color: inherit;
text-decoration: inherit;
transition: background-color 0.3s ease-in-out;
background-color: #fff;

&:hover {
text-decoration: inherit;
background-color: var(--color-light-blue);
}
}
10 changes: 7 additions & 3 deletions src/gatsby/models/docs/createPages.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path')
const GithubSlugger = require('github-slugger')

const slugger = new GithubSlugger()
Expand Down Expand Up @@ -43,6 +44,7 @@ const createPages = async ({ graphql, actions }) => {
id
rawMarkdownBody
slug
template
}
}
}
Expand All @@ -54,17 +56,19 @@ const createPages = async ({ graphql, actions }) => {
throw docsResponse.errors
}

const docComponent = require.resolve('../../../templates/doc-home.tsx')
const docComponent = require.resolve('../../../templates/doc.tsx')

docsResponse.data.docs.edges.forEach(doc => {
const {
node: { id, slug, rawMarkdownBody }
node: { id, slug, rawMarkdownBody, template }
} = doc
const headings = parseHeadings(rawMarkdownBody)

if (slug) {
actions.createPage({
component: docComponent,
component: template
? require.resolve(path.resolve('src', 'templates', template + '.tsx'))
: docComponent,
path: slug,
context: {
id,
Expand Down
3 changes: 2 additions & 1 deletion src/gatsby/models/docs/createSchemaCustomization.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ async function createSchemaCustomization(api) {
name: 'DocsPage',
interfaces: ['Node'],
fields: {
...markdownParentFields
...markdownParentFields,
template: 'String'
}
})
]
Expand Down
3 changes: 2 additions & 1 deletion src/gatsby/models/docs/onCreateMarkdownContentNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function createMarkdownDocsNode(api, { parentNode }) {
const fieldData = {
slug,
rawMarkdownBody: node.rawMarkdownBody,
sourcePath: relativePath
sourcePath: relativePath,
template: node.frontmatter.template
}

const docNode = {
Expand Down
3 changes: 2 additions & 1 deletion src/gatsby/models/markdown-content/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ module.exports = {
timeToRead: {
type: 'String!',
resolve: parentResolverPassthrough()
}
},
template: 'String'
}
6 changes: 3 additions & 3 deletions src/templates/doc-home.tsx → src/templates/doc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import SEO from '../components/SEO'

import Documentation from '../components/Documentation'

interface IDocHomePageProps {
interface IDocPageProps {
data: {
page: {
htmlAst: Node
Expand All @@ -19,7 +19,7 @@ interface IDocHomePageProps {
}
}

const DocHomePage: React.FC<IDocHomePageProps> = ({
const DocPage: React.FC<IDocPageProps> = ({
data,
pageContext: { slug, headings }
}) => {
Expand All @@ -37,7 +37,7 @@ const DocHomePage: React.FC<IDocHomePageProps> = ({
)
}

export default DocHomePage
export default DocPage

export const pageQuery = graphql`
query DocPage($id: String!) {
Expand Down
1 change: 1 addition & 0 deletions static/img/home_placeholder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.