Skip to content

Instantly share code, notes, and snippets.

Avatar

DJ dwalkr

  • Forestry.io
  • Maryland, USA
View GitHub Profile
View _.jsx
useEffect(() => {
setHasError(false)
if (!editMode) {
import(`../content/${slug}.json`)
.then((content) => {
setContent(content.default)
})
.catch((e) => {
setHasError(true)
})
View _.jsx
const [data] = useForm({
//...
loadInitialValues: editMode ? loadData : async () => content
})
const layoutContent = useMemo(() => {
if (editMode && data.keys().length > 0) return data
return content
}, [editMode, content, data]
View _.js
const [editMode] = useEditMode()
const { loadData } = useGithubFile({
path: 'src/navigation.json',
parse: JSON.parse,
serialize: JSON.stringify,
})
const [githubNavItems, setGithubNavItems] = useState(navigation)
useEffect(() => {
View _.js
const { loadData, commit } = useGithubFile({
path: 'src/content/home.json',
parse: JSON.parse,
serialize: JSON.stringify,
})
useForm({
//...
onSubmit: async (values: any) => commit(values),
loadInitialValues: loadData,
View a.js
export const Page = (props) => {
const [foo, setFoo] = useState('foo')
useForm({
//...
loadInitialValues: async () => {
setFoo('bar')
console.log(foo) // 'bar'
}
onSubmit: async (values) => {
View gulpfile.js
/**
* This is an example gulpfile.js for orchestrating a Webpack build alongside the Hugo static site generator.
*
* This example assumes you already have Webpack installed and configured in your project.
*
* To get started, install Gulp and BrowserSync with the following command:
* npm install gulp browser-sync
*
* Then add this file to your project and name it gulpfile.js
*/
View gist:af450931a1dceb5ac0f25a2bd7471197
npx create-static-site testhugo3 --template hugo
npx: installed 64 in 3.889s
Creating a new Static Site in /home/dj/Forestry/testhugo3.
Installing packages. This might take a couple of minutes.
Installing static-scripts...
yarn add v1.6.0
warning package.json: No license field
You can’t perform that action at this time.