Comments (7)
this is almost identical to react-static, i would suggest using that.
from after.js.
@jaredpalmer yes yes a thousand times yes this
I was just about to fork this repo to add support for this (via static-site-generator-webpack-plugin
and extracting some bits of server.js
for reuse). Did you have a plan for how the user-facing API for export should work (e.g. how a user should specify a list of [possibly dynamically generated] routes, any hooks for pre/post build), so I can maybe send you a usable pull request someday?
from after.js.
Haven't given this too much thought. Was going to look at inspiration from react-static and a few other places.
Design Requirements
- Be able to easily leverage the filesystem for dynamically generated routes. So you can have a
posts
directory for a blog. - Avoid JSON route config if possible
- No trailing slashes because it's 2018, not 2008
from after.js.
My immediate use-case is to generate a bunch of blog routes from a Contentful space. On Gatsby, I'm currently doing one GraphQL query to pull in everything, then calling createPage
a bunch of times for both individual and archive pages.
Here, what seems nice off the top of my head (not having looked at react-static) is to have an async function in the config file that returns/resolves to an array/object with URIs and (optional) props, which an after export
script would use to build pages. This function could also serve as a "before" hook where I could (for example) pull CMS data down in one go, and have my getInitialProps
functions pull from that instead of HTTP.
Something like this:
// in after.config.js
const getPosts = require('./example-path/getPosts')
module.exports = {
exportPathMap: async () => {
// Returns an array of post objects. Where this function gets its data is irrelevant — it could be an API, the filesystem, whatever
const allPosts = await getPosts()
const postsExportMap = allPosts.reduce((postsMap, post) => {
postsMap[`/posts/${posts.year}/${posts.slug}`] = { post }
return postsMap
}, {})
return postsExportMap
}
}
If someone wanted to pull in Jekyll-style files as a data source — instead of or in addition to API data like Contentful — that'd be as simple as traversing that directory, processing the files, and including them in the return array.
If some kind person wanted to write (or has already written?) a module that reads a directory of .md
files, does Remark and GreyMatter on them, and returns them as an array of JS objects, that could come in quite handy here. 😉
from after.js.
N.B. - This is the same function signature as Next's static export, but values are props instead of Next routing objects, allowing the data that's generating the route map to also be passed into the components, to obviate the need for potentially dozens/hundreds of add'l API calls.
These routes are to be used in addition to the _routes.js
file, so that an After site could render things dynamically in dev (or as a live preview environment for post drafts coming from an API), but statically in prod, or any mix of the two.
It would probably not be hard to have this function also pass in a component, and skip the routes table entirely. I personally would want to keep the routes file so that I can set up the preview environment thingy I mentioned, but it could work either way.
from after.js.
What happened to this? Was it dropped?
from after.js.
Would have been a really nice feature to tag with Razzle's export somehow.
from after.js.
Related Issues (20)
- Error on using transitionBehavior="instant" HOT 3
- Make After.js http server agnostic HOT 3
- Grommet integration example HOT 1
- Is After.js not meant to support the latest version of Razzle? HOT 2
- After.js and @loadable/component it works incorrectly? HOT 5
- Cannot find module 'undefined', chunks.json not created in build folder after upgrading razzle to 4.1.0 HOT 2
- `TypeError: reactRouterDom.withRouter is not a function` after using `create-after-app` HOT 4
- Does After.js support something similar to next/head? HOT 2
- problematic set status after redirect HOT 1
- Brotli compression algorithm support on production? HOT 2
- HMR error: process is not defined HOT 3
- redirectTo not working, Throwing Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client HOT 4
- Component not triggering after browser back button HOT 1
- How to use Graphql with apollo-client or any other client in afterJS?
- loadable-component with After.js - any sample repo to get me started?
- How to prevent calling getInitialProps when follow the nested route?
- create-after-app issue with dependencies conflict
- Hash links are re-rendering page
- Status of this project HOT 16
- Potential bug with route matching HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from after.js.