takeshape-routing
takeshape-routing
is a module designed to be used on the frontend of a site generated with TakeShape. It is library agnostic so it can be used with React, Vue, etc.
Installation
npm install --save takeshape-routing
Routing
The route
function is used to generate links on the client side. It allows you to create links to your static site with content fetched from the TakeShape GraphQL API. It's especially useful when building out dynamic search or taxonomy pages.
route
is a curried function which consumes the following params
config
- Object - Thetsg.yml
config object useyaml-loader
to import itrouteName
- String - The name of the desired routecontent
- Object - An object containing the properties referenced in the route string
tsg.yml
templatePath: src/templatesstaticPath: staticbuildPath: build routes: post: path: /blog/:title/ template: pages/posts/individual.html
search-result-link.jsx
;; const route = ; { return <a href=>contenttitle</a> ;}
where the content
prop would be:
Rendered HTML:
How TakeShape Routing Works
Image URLs
getImageUrl
converts asset paths into URLs suitable for use in an <img>
tag.
; <img src=/> <img src=/> // image resized to 300x250
TakeShape uses Imgix as its image CDN.
Imgix provides rich suite of image manipulation capatbilities that are accessible using the second argument of getImageUrl
.
See their docs for all the possibilites!
Asset URLs
Not all assets in TakeShape are images and sometimes you just want a simple download link. Use getAssetUrl
in this case.
; <a href= download>Download Me</a>