Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Serve Static Pages at Scale

Serve Static Pages at Scale

Serve Static Pages at Scale presentation from Static-Sites Meetup Berlin by Mouafa Ahmed

mouafa ahmed

November 21, 2017
Tweet

More Decks by mouafa ahmed

Other Decks in Technology

Transcript

  1. 3

  2. The Challenge Imagine that your marketing team came to you

    asking for: • A fast way to publish hundreds of landing pages. • Support of different languages. • The ability to change the content of those landing pages without your intervention. 4
  3. 5

  4. 6

  5. A History of solutions • Python script that generate static

    pages with all the available localisation. • Node.js script that basically do the same thing. 7
  6. What we did right • Ability to handle many languages

    • Putting content in Contentful • The ability to change the content without touching the code 8
  7. What we missed • The ability to change the content

    without redeploying • Mixing template with content in Contentful • A better Developer eXperience 9
  8. 12

  9. 13

  10. 14

  11. 15

  12. 17

  13. meta.json { "template": "ebook", "relations": [ { "contentfulID": "57tKmI41k4WQsUS28ckG0", "sectionID":

    "section1" }, { "contentfulID": "1R3Eo49Ez6MeQYsUcoYCm", "sectionID": "section2" }, { "contentfulID": "59zeHjZ9QAcKyESsu4Iue", "sectionID": "section3" } ] } 19
  14. Prepare the local context (content + i18n + linker) content

    Motor Render Resolve template Pug render With the prepared context rendered page template Lang, country 23
  15. 24

  16. Environment variables NODE_ENV = development MOTOR_PORT = 4000 SPACE_ID =

    contentful_SPACE_ID ACCESS_TOKEN = contentful_ACCESS_TOKEN 25
  17. Configuration const motor = require('motor') const path = require('path') const

    config = { path: { env: path.resolve(__dirname, '.env'), views: path.resolve(__dirname, 'views'), templates: path.resolve(__dirname, 'templates'), i18n: path.resolve(__dirname, 'i18n') }, static: [ { directory: 'static', path: path.resolve(__dirname, 'static') } ], supportedLangs: ['en', 'de'] } motor(config) 26
  18. 27