Skip to content

Commit b390d10

Browse files
committed
refactor
1 parent d0f485a commit b390d10

File tree

7 files changed

+79
-66
lines changed

7 files changed

+79
-66
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,5 @@ yarn-error.log
7474

7575
# Codegen stuff
7676
src/__generated__/
77+
78+
.idea/

notes/ContributingToCodePage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ src/content/code
2929

3030
We'd love any new project to include a few paragraphs describing its goals and usage, the goal here is to make it easy for people to decide between options.
3131

32-
Here's an optimal example example of what we're looking for:
32+
Here's an optimal example of what we're looking for:
3333

34-
- It uses yml frontmatter to provide additional information like repo, npm
34+
- It uses yaml frontmatter to provide additional information like repo, npm
3535
- It explains itself in the 'description' then fills fleshes out that description with some code samples
3636

3737
````md

notes/NewSiteArchitecture.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
This page is effectively a marketing page for GraphQL and should be the visual, scrollable version of the "Introducing GraphQL" conference talks and should be rich with visual metaphor and illustration and take advantage of whitespace to make individual salient points.
1010

11-
Above the fold, this page should succinctly explain what GraphQL is and illustrate with a simple (editable) query/response example. Before scrolling you should understand the following:
11+
Above the fold, this page should succinctly explain what GraphQL is and illustrate with a simple (editable) query/response example. Before scrolling, you should understand the following:
1212

1313
* GraphQL solves the same problem as REST.
14-
* GraphQL is an query language for APIs (and not Databases).
14+
* GraphQL is a query language for APIs (and not Databases).
1515
* GraphQL is sent by client applications, such as an iOS app.
1616
* GraphQL is evaluated by a web service and often returned as JSON.
1717
* GraphQL services provide a complete description of your data with a type system.

scripts/sort-libraries.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const getGitHubStats = async githubRepo => {
106106
const formattedStars = numbro(stars).format({
107107
average: true,
108108
});
109-
109+
110110
const releases = [];
111111
if (repo.tags && repo.tags.nodes && repo.tags.nodes.length && repo.tags.nodes[0].target.target && repo.tags.nodes[0].target.target.pushedDate) {
112112
releases.push(repo.tags.nodes[0].target.target.pushedDate);
@@ -117,7 +117,7 @@ const getGitHubStats = async githubRepo => {
117117
if(owner.includes("graphql")) {
118118
console.log({ releases, repoName })
119119
}
120-
120+
121121
const lastRelease = releases.filter(Boolean).sort().reverse()[0]
122122

123123
return {

src/pages/brand.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export default ({ pageContext }: PageProps<{}, { sourcePath: string }>) => {
136136
<a
137137
href="https://fonts.google.com/specimen/Rubik?sidebar.open=true&selection.family=Rubik:wght@300&preview.text=GraphQL&preview.text_type=custom"
138138
target="_blank"
139+
rel="noreferrer"
139140
>
140141
Rubik Light
141142
</a>
@@ -147,6 +148,7 @@ export default ({ pageContext }: PageProps<{}, { sourcePath: string }>) => {
147148
<a
148149
href="https://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL"
149150
target="_blank"
151+
rel="noreferrer"
150152
>
151153
Open Font License
152154
</a>

src/pages/code.tsx

Lines changed: 65 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { PageProps } from "gatsby"
22
import { AnchorLink } from "gatsby-plugin-anchor-links"
3-
import React, { useState } from "react"
3+
import React, { useState, Fragment } from "react"
44
import Layout from "../components/Layout"
55
import Marked from "../components/Marked"
66
import Seo from "../components/Seo"
@@ -20,16 +20,16 @@ interface Language {
2020
name: string
2121
totalStars: number
2222
categoryMap: {
23-
Client: Array<Library>
24-
Server: Array<Library>
23+
Client: Library[]
24+
Server: Library[]
2525
}
2626
}
2727

2828
interface PageContext {
29-
languageList: Array<Language>
29+
languageList: Language[]
3030
otherLibraries: {
31-
Services: Array<Library>
32-
Tools: Array<Library>
31+
Services: Library[]
32+
Tools: Library[]
3333
}
3434
sourcePath: string
3535
}
@@ -38,7 +38,7 @@ export function buildLanguagesMenu(pageContext: PageContext) {
3838
return (
3939
<div className="language-boxes">
4040
{pageContext.languageList
41-
?.map(langeuage => langeuage?.name!)
41+
?.map(language => language?.name!)
4242
.filter(Boolean)
4343
.map(languageName => {
4444
const slug = toSlug(languageName)
@@ -65,13 +65,22 @@ export function buildLibraryContent(
6565
return (
6666
<div className="library-info">
6767
<div className="library-details">
68-
<a className="library-name" href={library.url} target="_blank">
68+
<a
69+
className="library-name"
70+
href={library.url}
71+
target="_blank"
72+
rel="noreferrer"
73+
>
6974
<p>{library.name}</p>
7075
</a>
7176
{library.github && (
7277
<div className="library-detail">
7378
<b>GitHub</b>
74-
<a href={`https://github.com/${library.github}`} target="_blank">
79+
<a
80+
href={`https://github.com/${library.github}`}
81+
target="_blank"
82+
rel="noreferrer"
83+
>
7584
{library.github}
7685
</a>
7786
</div>
@@ -93,6 +102,7 @@ export function buildLibraryContent(
93102
<a
94103
href={`https://rubygems.org/gems/${library.gem}`}
95104
target="_blank"
105+
rel="noreferrer"
96106
>
97107
{library.gem}
98108
</a>
@@ -180,7 +190,6 @@ export function buildLibraryCategoryContent(
180190
</div>
181191
)
182192
}
183-
return
184193
}
185194

186195
const categorySlugMap = [
@@ -190,52 +199,54 @@ const categorySlugMap = [
190199
]
191200

192201
export function buildLanguagesContent(pageContext: any) {
193-
const elements = []
194-
for (const languageObj of pageContext.languageList) {
195-
const languageName = languageObj.name
196-
const libraryCategories = languageObj.categoryMap
197-
const filteredCategorySlugMap = categorySlugMap.filter(
198-
([libraryCategoryName]) =>
199-
libraryCategories[libraryCategoryName as any]?.length
200-
)
201-
const languageSlug = toSlug(languageName)
202-
elements.push(
203-
<div className="language-content" id={languageSlug}>
204-
<div className="language-header">
205-
<h2 className="language-title">{languageName}</h2>
206-
{filteredCategorySlugMap.length > 1 && (
207-
<p className="language-categories-permalinks">
208-
{filteredCategorySlugMap.map(
209-
([libraryCategoryName, categorySlug], i) => (
210-
<>
211-
<AnchorLink
212-
title={`${languageSlug} ${categorySlug}`}
213-
className="language-category-permalink"
214-
to={`#${languageSlug}-${categorySlug}`}
215-
>
216-
{libraryCategoryName}
217-
</AnchorLink>
218-
{i < filteredCategorySlugMap.length - 1 && " / "}
219-
</>
202+
return (
203+
<div className="languages-content">
204+
{pageContext.languageList.map(languageObj => {
205+
const languageName = languageObj.name
206+
const libraryCategories = languageObj.categoryMap
207+
const filteredCategorySlugMap = categorySlugMap.filter(
208+
([libraryCategoryName]) =>
209+
libraryCategories[libraryCategoryName as any]?.length
210+
)
211+
const languageSlug = toSlug(languageName)
212+
return (
213+
<div className="language-content" id={languageSlug}>
214+
<div className="language-header">
215+
<h2 className="language-title">{languageName}</h2>
216+
{filteredCategorySlugMap.length > 1 && (
217+
<p className="language-categories-permalinks">
218+
{filteredCategorySlugMap.map(
219+
([libraryCategoryName, categorySlug], i) => (
220+
<Fragment key={libraryCategoryName}>
221+
<AnchorLink
222+
title={`${languageSlug} ${categorySlug}`}
223+
className="language-category-permalink"
224+
to={`#${languageSlug}-${categorySlug}`}
225+
>
226+
{libraryCategoryName}
227+
</AnchorLink>
228+
{i < filteredCategorySlugMap.length - 1 && " / "}
229+
</Fragment>
230+
)
231+
)}
232+
</p>
233+
)}
234+
</div>
235+
<div className="library-categories">
236+
{filteredCategorySlugMap.map(([categoryName, categorySlug]) =>
237+
buildLibraryCategoryContent(
238+
libraryCategories,
239+
categoryName,
240+
`${languageSlug}-${categorySlug}`,
241+
pageContext
220242
)
221243
)}
222-
</p>
223-
)}
224-
</div>
225-
<div className="library-categories">
226-
{filteredCategorySlugMap.map(([categoryName, categorySlug]) =>
227-
buildLibraryCategoryContent(
228-
libraryCategories,
229-
categoryName,
230-
`${languageSlug}-${categorySlug}`,
231-
pageContext
232-
)
233-
)}
234-
</div>
235-
</div>
236-
)
237-
}
238-
return <div className="languages-content">{elements}</div>
244+
</div>
245+
</div>
246+
)
247+
})}
248+
</div>
249+
)
239250
}
240251

241252
export default ({ pageContext }: PageProps<{}, PageContext>) => {

src/utils/useFAQAccordion.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const useFAQAccordion = () => {
2424
}
2525

2626
useEffect(() => {
27-
const hash = window.location.hash ? window.location.hash.split("#")[1] : ""
27+
const hash = location.hash ? location.hash.split("#")[1] : ""
2828

2929
if (hash && buttonCreated) {
3030
const anchor = document && document.getElementById(hash)
@@ -57,19 +57,17 @@ export const useFAQAccordion = () => {
5757
const element =
5858
e.target.localName === "button" ? e.target : e.target.parentNode
5959

60-
6160
window.history.replaceState(
6261
{},
6362
"",
6463
"#" + e.target.getElementsByTagName("a")[0].id
6564
)
6665
window.history.scrollRestoration = "manual"
66+
e.target.classList.toggle("open")
6767

6868
if (e.target.localName === "button") {
69-
e.target.classList.toggle("open")
7069
e.target.getElementsByTagName("h3")[0].classList.toggle("open")
7170
} else {
72-
e.target.classList.toggle("open")
7371
e.target.parentNode.classList.toggle("open")
7472
}
7573

@@ -79,5 +77,5 @@ export const useFAQAccordion = () => {
7977
document.addEventListener("click", toggleClasses)
8078

8179
return () => document.removeEventListener("click", toggleClasses)
82-
}, [typeof window !== 'undefined' ? window.location.hash : null])
83-
}
80+
}, [typeof window !== 'undefined' ? location.hash : null])
81+
}

0 commit comments

Comments
 (0)