Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Use module path aliases for imports (#156)
Browse files Browse the repository at this point in the history
* Use module path aliases for imports

* Use interface for MarkdownFileWithUrl

Co-authored-by: ltagliaferri <[email protected]>
  • Loading branch information
katjuell and ltagliaferri authored Aug 11, 2021
1 parent 1445037 commit fa27418
Show file tree
Hide file tree
Showing 32 changed files with 114 additions and 122 deletions.
3 changes: 1 addition & 2 deletions components/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import CreativeCommonsNotice from '@components/atoms/CreativeCommonsNotice'
import GithubIcon from 'mdi-react/GithubIcon'
import LinkedinIcon from 'mdi-react/LinkedinIcon'
import TwitterIcon from 'mdi-react/TwitterIcon'
import YouTubeIcon from 'mdi-react/YoutubeIcon'
import Link from 'next/link'
import React from 'react'

import CreativeCommonsNotice from '../atoms/CreativeCommonsNotice'

import {
StyledFooterWrapper,
StyledFooterContainer,
Expand Down
5 changes: 2 additions & 3 deletions components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import HeaderCta from '@components/atoms/HeaderCta'
import Row from '@components/atoms/Row'
import React from 'react'

import HeaderCta from '../atoms/HeaderCta'
import Row from '../atoms/Row'

import { StyledHeaderImage, StyledHeaderText } from './HeaderStyles'

interface Props {
Expand Down
3 changes: 1 addition & 2 deletions components/NavBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import Button from '@components/atoms/Button'
import MenuDownIcon from 'mdi-react/MenuDownIcon'
import MenuIcon from 'mdi-react/MenuIcon'
import MenuUpIcon from 'mdi-react/MenuUpIcon'
import React, { useState } from 'react'

import Button from '../atoms/Button'

import {
StyledNavBarWrapper,
StyledNavBarContainer,
Expand Down
5 changes: 2 additions & 3 deletions components/atoms/AuthorCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Card from '@components/atoms/Card'
import ContentCard from '@components/atoms/ContentCard'
import React from 'react'

import Card from '../Card'
import ContentCard from '../ContentCard'

import { StyledAuthorImage } from './AuthorCardStyles'

interface Props {
Expand Down
7 changes: 3 additions & 4 deletions components/atoms/AuthorCardList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import AuthorCard from '@components/atoms/AuthorCard'
import Column from '@components/atoms/Column'
import AuthorCollection from '@interfaces/AuthorCollection'
import React from 'react'

import AuthorCollection from '../../../interfaces/AuthorCollection'
import AuthorCard from '../AuthorCard'
import Column from '../Column'

import { StyledAuthorCardList } from './AuthorCardListStyles'

interface Props {
Expand Down
5 changes: 2 additions & 3 deletions components/atoms/CollectionView/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Card from '@components/atoms/Card'
import MarkdownFile from '@interfaces/MarkdownFile'
import Link from 'next/link'
import React from 'react'

import MarkdownFile from '../../../interfaces/MarkdownFile'
import Card from '../Card'

import {
StyledCollectionHeader,
StyledCollectionBody,
Expand Down
3 changes: 1 addition & 2 deletions components/atoms/ContentCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Card from '@components/atoms/Card'
import Link from 'next/link'
import React from 'react'

import Card from '../Card'

import {
StyledCardBody,
StyledCardTitle,
Expand Down
9 changes: 4 additions & 5 deletions components/atoms/ContentCardList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import Column from '@components/atoms/Column'
import ContentCard from '@components/atoms/ContentCard'
import Row from '@components/atoms/Row'
import MarkdownFileWithUrl from '@interfaces/MarkdownFileWithUrl'
import React from 'react'

import { MarkdownFileWithUrl } from '../../../types/MarkdownFileWithUrl'
import Column from '../Column'
import ContentCard from '../ContentCard'
import Row from '../Row'

interface Props {
records: MarkdownFileWithUrl[]
}
Expand Down
12 changes: 10 additions & 2 deletions components/atoms/CreativeCommonsNotice/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ const CreativeCommonsNotice: React.FunctionComponent = () => (
<StyledCreativeCommonsNoticeContainer>
<StyledCreativeCommonsNoticeText>
This work is licensed under a{' '}
<StyledCreativeCommonsLink href={creativeCommonsUrl}>
<StyledCreativeCommonsLink
href={creativeCommonsUrl}
target="_blank"
rel="noreferrer"
>
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
</StyledCreativeCommonsLink>
</StyledCreativeCommonsNoticeText>
<a href={creativeCommonsUrl}>
<a
href={creativeCommonsUrl}
target="_blank"
rel="noreferrer"
>
<StyledCreativeCommonsImage alt="Creative Commons badge" src="/creative-commons-by-nc-sa.svg" />
</a>
</StyledCreativeCommonsNoticeContainer>
Expand Down
7 changes: 3 additions & 4 deletions components/atoms/SourcegraphSearch/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Button from '@components/atoms/Button'
import Card from '@components/atoms/Card'
import Column from '@components/atoms/Column'
import React, { useState } from 'react'

import Button from '../Button'
import Card from '../Card'
import Column from '../Column'

import { StyledSearchBody, StyledSearchInput } from './SourcegraphSearchStyles'

interface Props {
Expand Down
8 changes: 4 additions & 4 deletions components/layouts/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Container from '@components/atoms/Container'
import { GoogleTagManagerScriptTag, GoogleTagManagerNoscriptFrame } from '@components/atoms/GoogleTagManager'
import Footer from '@components/Footer'
import NavBar from '@components/NavBar'
import Head from 'next/head'
import * as React from 'react'

import { googleTagManagerId } from '../../site-config'
import Container from '../atoms/Container'
import { GoogleTagManagerScriptTag, GoogleTagManagerNoscriptFrame } from '../atoms/GoogleTagManager'
import Footer from '../Footer'
import NavBar from '../NavBar'

const SITE_TITLE = 'Sourcegraph Learn'

Expand Down
8 changes: 3 additions & 5 deletions components/layouts/PageLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import Column from '@components/atoms/Column'
import Row from '@components/atoms/Row'
import Layout, { Props as LayoutProps, MetaTags } from '@components/layouts/Layout'
import React from 'react'

import Column from '../atoms/Column'
import Row from '../atoms/Row'

import Layout, { Props as LayoutProps, MetaTags } from './Layout'

interface Props extends LayoutProps {
leftColumn?: React.ReactNode
rightColumn?: React.ReactNode
Expand Down
19 changes: 9 additions & 10 deletions components/templates/ArticleTemplate/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import Button from '@components/atoms/Button'
import CollectionView from '@components/atoms/CollectionView'
import EmbeddedYoutubeVideo from '@components/atoms/EmbeddedYoutubeVideo'
import GifLikeVideo from '@components/atoms/GifLikeVideo'
import SourcegraphSearch from '@components/atoms/SourcegraphSearch'
import TocWrapper from '@components/atoms/TocWrapper'
import { MetaTags } from '@components/layouts/Layout'
import PageLayout from '@components/layouts/PageLayout'
import RecordCollection from '@interfaces/RecordCollection'
import RegexIcon from 'mdi-react/RegexIcon'
import { MDXRemote, MDXRemoteSerializeResult } from 'next-mdx-remote'
import React from 'react'
import rehypeReact from 'rehype-react'
import unified from 'unified'
import { Node } from 'unist'

import RecordCollection from '../../../interfaces/RecordCollection'
import Button from '../../atoms/Button'
import CollectionView from '../../atoms/CollectionView'
import EmbeddedYoutubeVideo from '../../atoms/EmbeddedYoutubeVideo'
import GifLikeVideo from '../../atoms/GifLikeVideo'
import SourcegraphSearch from '../../atoms/SourcegraphSearch'
import TocWrapper from '../../atoms/TocWrapper'
import { MetaTags } from '../../layouts/Layout'
import PageLayout from '../../layouts/PageLayout'

import {
StyledHeaderImage,
StyledAuthorByline,
Expand Down
2 changes: 1 addition & 1 deletion interfaces/MarkdownFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import FrontMatter from './FrontMatter'
import FrontMatter from '@interfaces/FrontMatter'

export default interface MarkdownFile {
slug: string
Expand Down
5 changes: 5 additions & 0 deletions interfaces/MarkdownFileWithUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import MarkdownFile from '@interfaces/MarkdownFile'

export default interface MarkdownFileWithUrl extends MarkdownFile {
url: string
}
2 changes: 1 addition & 1 deletion interfaces/RecordCollection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Description of the fields that are supported in individual record collections
*/
import MarkdownFile from './MarkdownFile'
import MarkdownFile from '@interfaces/MarkdownFile'

export default interface RecordCollection {
title: string
Expand Down
7 changes: 3 additions & 4 deletions lib/loadAllRecords.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import MarkdownFile from '../interfaces/MarkdownFile'

import listAllRecords from './listAllRecords'
import loadMarkdownFile from './loadMarkdownFile'
import MarkdownFile from '@interfaces/MarkdownFile'
import listAllRecords from '@lib/listAllRecords'
import loadMarkdownFile from '@lib/loadMarkdownFile'

export default async function loadAllRecords(baseDirectory: string, includeUnlisted: boolean = false): Promise<MarkdownFile[]> {
const records = await listAllRecords(baseDirectory)
Expand Down
5 changes: 2 additions & 3 deletions lib/loadAuthorCollections.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { promises as fs } from 'fs'

import AuthorCollection from '@interfaces/AuthorCollection'
import { normalizeAuthorCollectionDefinition } from '@util/validators'
import yaml from 'js-yaml'

import AuthorCollection from '../interfaces/AuthorCollection'
import { normalizeAuthorCollectionDefinition } from '../util/validators'

interface AuthorCollections {
authors: AuthorCollection[]
}
Expand Down
5 changes: 2 additions & 3 deletions lib/loadMarkdownFile.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { promises as fs } from 'fs'
import path from 'path'

import MarkdownFile from '@interfaces/MarkdownFile'
import { normalizeFrontMatter } from '@util/validators'
import greyMatter from 'gray-matter'

import MarkdownFile from '../interfaces/MarkdownFile'
import { normalizeFrontMatter } from '../util/validators'

function removeExtension(filename: string): string {
const parts = filename.split('.')
if (parts.length > 1) {
Expand Down
12 changes: 5 additions & 7 deletions lib/loadRecordCollections.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { promises as fs } from 'fs'

import MarkdownFile from '@interfaces/MarkdownFile'
import RecordCollection from '@interfaces/RecordCollection'
import RecordCollectionDefinition from '@interfaces/RecordCollectionDefinition'
import loadAllRecords from '@lib/loadAllRecords'
import { normalizeRecordCollectionDefinition } from '@util/validators'
import yaml from 'js-yaml'

import MarkdownFile from '../interfaces/MarkdownFile'
import RecordCollection from '../interfaces/RecordCollection'
import RecordCollectionDefinition from '../interfaces/RecordCollectionDefinition'
import { normalizeRecordCollectionDefinition } from '../util/validators'

import loadAllRecords from './loadAllRecords'

interface RecordCollections {
recordCollections: RecordCollection[]
}
Expand Down
3 changes: 1 addition & 2 deletions lib/serializeMdxSource.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import MarkdownFile from '@interfaces/MarkdownFile'
import rehypePrism from '@mapbox/rehype-prism'
import mdastUtilToHast from 'mdast-util-to-hast'
import mdastUtilToc from 'mdast-util-toc'
Expand All @@ -8,8 +9,6 @@ import rehypeAutolinkHeadings from 'rehype-autolink-headings'
import rehypeSlug from 'rehype-slug'
import { Node } from 'unist'

import MarkdownFile from '../interfaces/MarkdownFile'

/**
* Classes to add to elements in the rendered markdown (after the HTML is
* generated). This is used to add utility styles to elements in markdown
Expand Down
5 changes: 2 additions & 3 deletions pages/404.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Layout from '@components/layouts/Layout'
import ErrorTemplate from '@components/templates/ErrorTemplate'
import * as React from 'react'

import Layout from '../components/layouts/Layout'
import ErrorTemplate from '../components/templates/ErrorTemplate'

export const NotFoundPage: React.FunctionComponent = () => (
<Layout>
<ErrorTemplate />
Expand Down
14 changes: 7 additions & 7 deletions pages/[slug].tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import loadAllRecords from '@lib/loadAllRecords'
import loadMarkdownFile from '@lib/loadMarkdownFile'
import loadRecordCollections from '@lib/loadRecordCollections'
import serializeMdxSource from '@lib/serializeMdxSource'
import getQueryParameter from '@util/getQueryParameters'
import omitUndefinedFields from '@util/omitUndefinedFields'
import slugToTitleCase from '@util/slugToTitleCase'
import { GetStaticPaths, GetStaticProps } from 'next'

import ArticleTemplate, { Props as ArticleTemplateProps } from '../components/templates/ArticleTemplate'
import loadAllRecords from '../lib/loadAllRecords'
import loadMarkdownFile from '../lib/loadMarkdownFile'
import loadRecordCollections from '../lib/loadRecordCollections'
import serializeMdxSource from '../lib/serializeMdxSource'
import getQueryParameter from '../util/getQueryParameters'
import omitUndefinedFields from '../util/omitUndefinedFields'
import slugToTitleCase from '../util/slugToTitleCase'

export const getStaticPaths: GetStaticPaths = async () => {
const posts = await loadAllRecords('posts', true)
Expand Down
2 changes: 1 addition & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AppProps } from 'next/app'
import React from 'react'

import '../styles/styles.scss'
import '@styles/styles.scss'

const App: React.FunctionComponent<AppProps> = ({ Component, pageProps }) => <Component {...pageProps} />

Expand Down
16 changes: 6 additions & 10 deletions pages/authors/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import AuthorCardList from '@components/atoms/AuthorCardList'
import PageLayout from '@components/layouts/PageLayout'
import AuthorCollection from '@interfaces/AuthorCollection'
import loadAllRecords from '@lib/loadAllRecords'
import loadAuthorCollections from '@lib/loadAuthorCollections'
import omitUndefinedFields from '@util/omitUndefinedFields'
import { GetStaticProps } from 'next'
import React from 'react'

import AuthorCardList from '../../components/atoms/AuthorCardList'
import PageLayout from '../../components/layouts/PageLayout'
import AuthorCollection from '../../interfaces/AuthorCollection'
import MarkdownFile from '../../interfaces/MarkdownFile'
import loadAllRecords from '../../lib/loadAllRecords'
import loadAuthorCollections from '../../lib/loadAuthorCollections'
import omitUndefinedFields from '../../util/omitUndefinedFields'

export type MarkdownFileWithUrl = MarkdownFile & { url: string }

interface Props {
uniqueAuthors: AuthorCollection[]
}
Expand Down
12 changes: 6 additions & 6 deletions pages/guides/[slug].tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import loadAllRecords from '@lib/loadAllRecords'
import loadMarkdownFile from '@lib/loadMarkdownFile'
import serializeMdxSource from '@lib/serializeMdxSource'
import getQueryParameter from '@util/getQueryParameters'
import omitUndefinedFields from '@util/omitUndefinedFields'
import slugToTitleCase from '@util/slugToTitleCase'
import { GetStaticPaths, GetStaticProps } from 'next'

import ArticleTemplate, { Props as ArticleTemplateProps } from '../../components/templates/ArticleTemplate'
import loadAllRecords from '../../lib/loadAllRecords'
import loadMarkdownFile from '../../lib/loadMarkdownFile'
import serializeMdxSource from '../../lib/serializeMdxSource'
import getQueryParameter from '../../util/getQueryParameters'
import omitUndefinedFields from '../../util/omitUndefinedFields'
import slugToTitleCase from '../../util/slugToTitleCase'

export const getStaticPaths: GetStaticPaths = async () => {
const guides = await loadAllRecords('guides', true)
Expand Down
13 changes: 6 additions & 7 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import ContentCardList from '@components/atoms/ContentCardList'
import Header from '@components/Header'
import PageLayout from '@components/layouts/PageLayout'
import MarkdownFileWithUrl from '@interfaces/MarkdownFileWithUrl'
import loadAllRecords from '@lib/loadAllRecords'
import omitUndefinedFields from '@util/omitUndefinedFields'
import { GetStaticProps } from 'next'
import React from 'react'

import ContentCardList from '../components/atoms/ContentCardList'
import Header from '../components/Header'
import PageLayout from '../components/layouts/PageLayout'
import loadAllRecords from '../lib/loadAllRecords'
import { MarkdownFileWithUrl } from '../types/MarkdownFileWithUrl'
import omitUndefinedFields from '../util/omitUndefinedFields'

interface Props {
posts: MarkdownFileWithUrl[]
}
Expand Down
Loading

0 comments on commit fa27418

Please sign in to comment.