-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from NickYadance/v2
V2
- Loading branch information
Showing
87 changed files
with
802 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,5 @@ yarn-error.log* | |
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
.idea/ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import hljs from 'highlight.js/lib/core'; | ||
|
||
hljs.registerLanguage('go', require('highlight.js/lib/languages/go')) | ||
|
||
const codesDirectory = path.join(process.cwd(), 'posts', 'codes'); | ||
|
||
export function getAllCodeIds() { | ||
const fileNames = fs.readdirSync(codesDirectory); | ||
return fileNames.filter((filename) => filename.endsWith(".go")) | ||
.map((fileName) => { | ||
return { | ||
params: { | ||
id: fileName.replace(/\.go$/, ''), | ||
}, | ||
}; | ||
}); | ||
} | ||
|
||
export async function getCodeData(id) { | ||
const fullPath = path.join(codesDirectory, `${id}.go`); | ||
const fileContent = fs.readFileSync(fullPath, 'utf8'); | ||
|
||
return { | ||
id, | ||
html: hljs.highlight(fileContent, {language: 'go'}).value | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {getAllCodeIds, getCodeData} from "../../lib/codes"; | ||
import Layout from "../../components/layout"; | ||
|
||
export default function Code({data}) { | ||
return ( | ||
<Layout> | ||
<pre> | ||
<code className="hljs language-go"> | ||
<div dangerouslySetInnerHTML={{__html: data.html}}/> | ||
</code> | ||
</pre> | ||
</Layout> | ||
); | ||
} | ||
|
||
export async function getStaticPaths() { | ||
const paths = getAllCodeIds(); | ||
return { | ||
paths, | ||
fallback: false, | ||
}; | ||
} | ||
|
||
export async function getStaticProps({params}) { | ||
const codeData = await getCodeData(params.id); | ||
return { | ||
props: { | ||
data: codeData, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,6 @@ export default function Home({allPostsData}) { | |
))} | ||
</ul> | ||
</section> | ||
|
||
</Layout> | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.