diff --git a/gatsby-config.js b/gatsby-config.js index 285be52..4273e2c 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -1,5 +1,3 @@ -const path = require('path'); - require('dotenv').config() module.exports = { @@ -113,18 +111,32 @@ module.exports = { { resolve: `gatsby-transformer-remark`, options: { - plugins: [{ - resolve: `gatsby-remark-vscode`, - options: { - extensions: ['material-theme'], - theme: { - default: 'Light+ (default light)', - parentSelector: { - 'body.dark': 'One Dark Pro' - } + plugins: [ + { + resolve: `gatsby-remark-autolink-headers`, + options: { + offsetY: `140`, + icon: ``, + className: `anchor-link`, + maintainCase: true, + removeAccents: true, + isIconAfterHeader: true, + elements: [`h1`, `h2`, `h3`, `h4`], + } + }, + { + resolve: `gatsby-remark-vscode`, + options: { + extensions: ['material-theme'], + theme: { + default: 'Light+ (default light)', + parentSelector: { + 'body.dark': 'One Dark Pro' + } + }, } } - }] + ] } } ], diff --git a/src/components/Snippets/SnippetItem/SnippetItem.js b/src/components/Snippets/SnippetItem/SnippetItem.js new file mode 100644 index 0000000..371740d --- /dev/null +++ b/src/components/Snippets/SnippetItem/SnippetItem.js @@ -0,0 +1,26 @@ +import React from 'react'; +import { Link } from 'gatsby' + +const SnippetItem = ({ slug, title, date, tags }) => { + return ( +
+
+
+ {date} +
+
+ {title} +
+
+
+
+ {tags.map((tag, i) => ( +
{tag}
+ ))} +
+
+
+ ) +} + +export default SnippetItem \ No newline at end of file diff --git a/src/components/Snippets/Snippets.js b/src/components/Snippets/Snippets.js index 66c8235..4a7edfd 100644 --- a/src/components/Snippets/Snippets.js +++ b/src/components/Snippets/Snippets.js @@ -1,31 +1,9 @@ import React from 'react'; -import { Link } from 'gatsby' -import useSnippetsQuery from '../../hooks/useSnippetsQuery' -const Snippets = () => { - const { snippets } = useSnippetsQuery() +const Snippets = ({ children }) => { return (
-

Сниппеты

- {snippets.map(({ node: { frontmatter } }, i) => ( -
-
-
- {frontmatter.date} -
-
- {frontmatter.title} -
-
-
-
- {frontmatter.tags.map((tag, i) => ( -
{tag}
- ))} -
-
-
- ))} + {children}
) } diff --git a/src/components/Snippets/Snippets.scss b/src/components/Snippets/Snippets.scss index d1cfdaa..1bb9347 100644 --- a/src/components/Snippets/Snippets.scss +++ b/src/components/Snippets/Snippets.scss @@ -2,10 +2,13 @@ .snippets { margin-bottom: 40px; - & h2 { - margin-bottom: 20px; + & h1, h2 { + margin-bottom: 10px; font-size: 34px; } + p { + margin-bottom: 15px; + } & .snippet-item { display: flex; justify-content: space-between; diff --git a/src/pages/index.js b/src/pages/index.js index 42f0de1..a157bb4 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -3,14 +3,17 @@ import { Link, graphql } from 'gatsby' import { Main } from '../ui/ui' import { Grid, Row, Col } from 'react-flexbox-grid' import useSiteMetadataQuery from '../hooks/useSiteMetadataQuery' +import useSnippetsQuery from '../hooks/useSnippetsQuery' import SEO from '../components/SEO/SEO' import Layout from '../components/Layout/Layout' import Articles from '../components/Articles/Articles' import Snippets from '../components/Snippets/Snippets' +import SnippetItem from '../components/Snippets/SnippetItem/SnippetItem' import Offers from '../components/Offers/Offers' const IndexPage = ({ data: { allMarkdownRemark: edges } }) => { const { siteMetadata: { options: { articles: { onPage } } } } = useSiteMetadataQuery() + const { snippets } = useSnippetsQuery() let [limit, setLimit] = React.useState(onPage) return ( @@ -31,7 +34,18 @@ const IndexPage = ({ data: { allMarkdownRemark: edges } }) => { - + +

Сниппеты

+ {snippets.map(({ node: { frontmatter } }, i) => + + )} +
diff --git a/src/pages/snippets.js b/src/pages/snippets.js index 6a1b28a..6b2f5fc 100644 --- a/src/pages/snippets.js +++ b/src/pages/snippets.js @@ -1,11 +1,13 @@ import React from "react" +import { graphql } from "gatsby" import { Main } from '../ui/ui' import { Grid, Row, Col } from 'react-flexbox-grid' import SEO from '../components/SEO/SEO' import Layout from '../components/Layout/Layout' import Snippets from '../components/Snippets/Snippets' +import SnippetItem from '../components/Snippets/SnippetItem/SnippetItem' -const SnippetsPage = () => { +const SnippetsPage = ({ data: { allMarkdownRemark: { snippets } } }) => { return ( @@ -13,7 +15,19 @@ const SnippetsPage = () => { - + +

Сниппеты

+

Сниппеты это готовые решения некоторых проблем, которые можно скопировать и вставить

+ {snippets.map(({ node: { frontmatter } }, i) => + + )} +
@@ -22,4 +36,22 @@ const SnippetsPage = () => { ) } +export const query = graphql` +{ + allMarkdownRemark(filter: {frontmatter: {templateKey: {eq: "snippet"}}}, sort: {order: DESC, fields: frontmatter___date}) { + snippets: edges { + node { + frontmatter { + slug + title + tags + description + date(formatString: "D MMMM YYYY", locale: "ru-RU") + } + } + } + } +} +` + export default SnippetsPage diff --git a/src/styles/global.scss b/src/styles/global.scss index 1d1124d..3116898 100644 --- a/src/styles/global.scss +++ b/src/styles/global.scss @@ -55,15 +55,6 @@ .anchor-link.before { top: -2px!important; } - -.anchor { - display: block; - position: relative; - top: -150px; - visibility: hidden; - height: 0; -} - .inner { border-bottom: 1px solid #EBEBEB; padding-bottom: 15px; @@ -123,6 +114,27 @@ border-radius: 7px; margin: 0 0 15px; font-size: 16px; + & code { + padding-top: 10px; + } + &[data-language=js]:before { + content: "js"; + background: rgb(247, 223, 30); + } + &[data-language]:before { + color: #232129; + font-size: 0.75rem; + font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; + letter-spacing: 0.075em; + line-height: 1; + position: absolute; + left: 1.5rem; + text-align: right; + text-transform: uppercase; + top: 0px; + border-radius: 0px 0px 4px 4px; + padding: 0.25rem 0.5rem; + } } }