Giter VIP home page Giter VIP logo

agilitycms-eleventy-starter-2020's Introduction

Eleventy + Agility CMS

This is a sample Eleventy starter site that uses Agility CMS and aims to be a foundation for building fully static sites using 11ty and Agility CMS.

Getting Started

This is going to be fun! Let's go!

Agility CMS Account

The first thing you need is a free Agility CMS account. You can get that here πŸ‘‹. Once you create your Agility CMS account and ✨new✨ project name, come back here 🧐.

Clone the Repo

Now that you've got the content, you need the code!

Go ahead and clone the repo from github: πŸ‘‡

https://github.com/agility/agilitycms-eleventy-starter-2020.git

Install Dependencies

npm install or yarn install

Normally, this will create 9,999,999,999 files in your node_modules folder. Luckily, we're only gonna create 9,999,999 for this small demo.

YAY! πŸ‘πŸ‘πŸ‘

Environment Variables

You care about the environment don't you? πŸŒ²πŸŒ³πŸŒ΄πŸŽ‹

Either way, you're gonna need to grab a few variables from your Agility CMS account. Head over to the API Keys page in Agility CMS (https://manager.agilitycms.com/settings/apikeys) and grab your GUID, and API Keys for Preview and Fetch.

πŸ—„πŸ—„πŸ—„ Copy those into your .env file (rename it from .env.example)

Take Command of the cmd line

We've hooked up some neat commands to make your life easy.

πŸ”₯ Local πŸ”₯ Development πŸ”₯

If you want to run the project locally in preview mode, with a hot-reloading server, do this:

npm start or yarn start

Build It and They Will Browse

This is the entire reason for being for 11ty.

Preview Mode

npm run dev or yarn dev

Live or Production Mode

npm run build or yarn build

Wipe The Content 🧽

This example is using the Agility CMS Sync SDK. That content is cached in the node_modules folder. If you want to clear all that out, use this.

npm run cms-clear or yarn run cms-clear

The next time you run the project, the content will be pulled down again.

How this thing works πŸ€“

This projects uses nunjucks templates, and all the magic happens in the pages folder. Open that thing up and take a peek.

Pages Pages Pages

Agility CMS has the concept of pages and a sitemap. Those obejects are made available in the _data/pages.js data array.

Each page is rendered via the index.njk file, which just splits each page object into its own, er... page :). It also sets the permalink property to the path of the page object. Voila! Our Agility CMS pages are magically routed and rendered.

Layout -> Template -> Modules

Now let's take a look at how the templating works.

Each page uses the layout.njk template for the main html output.

Then, based on the agilitypage.templateFileName property, we load a .njk template file dynamically. In this case we only have the main-template.njk file.

In that template, we set the zoneName parameter and render the modules in the MainContentZone zone.

Each module zone has one or more modules in there, which are in turn rendered by a .njk file. I've put them in the /modules folder, and we've only got a few that are configured in this Agility CMS instance.

Hopefully, you can use the examples in this project to create your own modules.

A well-thought-out project with useful modules can empower your content editors with a set of building blocks for creating and updates the pages of your website.

Collections

This project is a blog template, so we have set of pages that are rendered based on the Posts list. Most of that is configured as a Dynamic Page in Agility CMS, so you don't have to do much to implement it, but you'll notice on the modules/postdetails.njk file that we use a property called agilitypage.dynamicPageItem. That object represents the Blog Post that we are currently rendering.

CSS + JavaScript

Tailwind CSS

To keep things super simple, this project makes use of free and amazing TailwindUI components, and it's all used via a dead simple https://cdn.jsdelivr.net/npm/@tailwindcss/ui@latest/dist/tailwind-ui.min.css file referenced in the header. No post-css or anything, at least not yet.

Alpine.js

We've pulled in a global reference to Alpine.js in the layout template, too. It's being used in a couple places to hide/show the mobile menu and the preview bar.

Want to learn more?

Amazing that you've gotten this far! Keep learning with me (Joel Varty) or the rest of the Agility CMS team.

Join us on Slack to answer questions and provide feedback directly to the team.

agilitycms-eleventy-starter-2020's People

Contributors

joelvarty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

stevewithington

agilitycms-eleventy-starter-2020's Issues

Error on `npm run dev`

I wanted to try out Agility with Eleventy but ran into some problems.
Following code snippet is error log on my console (running on Linux Mint Os based on Ubuntu 18.04)

> [email protected] dev
> run-s clean:files dev:* --print-label

[clean:files] 
[clean:files] > [email protected] clean:files
[clean:files] > del dist
[clean:files] 
[dev:cms    ] 
[dev:cms    ] > [email protected] dev:cms
[dev:cms    ] > NODE_ENV=development node agility/agility.sync.js sync
[dev:cms    ] 
[dev:cms    ] AgilityCMS => Starting Sync for en-us - preview mode. 
[dev:cms    ] AgilityCMS => Content Sync returned 28 item(s). 
[dev:cms    ] AgilityCMS => Page Sync returned 4 item(s). 
[dev:cms    ] AgilityCMS => Updating Sitemap channel website in en-us 
[dev:cms    ] AgilityCMS => URL Redirections Updated and Saved 
[dev:cms    ] AgilityCMS => Completed Sync for en-us - preview mode. 
[dev:css    ] 
[dev:css    ] > [email protected] dev:css
[dev:css    ] > NODE_ENV=production postcss src/css/index.css -o dist/styles.css
[dev:css    ] 
[dev:11ty   ] 
[dev:11ty   ] > [email protected] dev:11ty
[dev:11ty   ] > NODE_ENV=development eleventy
[dev:11ty   ] 
[dev:11ty   ] Agility CMS => Building site in preview mode.
[dev:11ty   ] > Cannot read property 'map' of undefined
[dev:11ty   ] 
[dev:11ty   ] `TypeError` was thrown:
[dev:11ty   ]     TypeError: Cannot read property 'map' of undefined
[dev:11ty   ]         at getAgilityContent (<project root folder>/src/_data/agilitypages.js:65:61)
[dev:11ty   ]         at async TemplateData.getDataValue (<project root folder>/node_modules/@11ty/eleventy/src/TemplateData.js:385:23)
[dev:11ty   ]         at async TemplateData.getAllGlobalData (<project root folder>/node_modules/@11ty/eleventy/src/TemplateData.js:228:18)
[dev:11ty   ]         at async TemplateData.getData (<project root folder>/node_modules/@11ty/eleventy/src/TemplateData.js:255:24)
ERROR: "dev:11ty" exited with 1.

Steps to reproduce this error

  1. Clone this repo
  2. run npm install
  3. add my own env variable to .env.example and rename it to .env
  4. run npm run dev

Expected behaviour

  1. Static site generated in preview mode

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.