入门
Eleventy v3.0.0 需要 Node.js
18 或更高版本才能运行。
你可以在终端窗口(或者命令行窗口)中运行 node --version
命令来检查是否安装了 Node。 (等等,什么是终端窗口?)如果找不到 Node 或者输出的版本号小于
18,那么在进入下一步之前,你需要 下载并安装 Node.js。
有视频教程吗?当然,看这里:6 分钟从零开始创建一个博客。
Step 1 创建项目目录
使用 mkdir
命令 (全称为 make directory)为你的项目创建一个目录:
mkdir eleventy-sample
然后使用 cd
命令(全称为 change directory)进入刚才创建的目录:
cd eleventy-sample
Step 2 安装 Eleventy
创建 package.json
文件
为你新建的项目安装 Eleventy 时需要一个 package.json
文件。
pnpm init
了解更多关于 pnpm 的信息(pnpm 需要单独安装)。
yarn init
了解更多关于 yarn 的信息(yarn 需要单独安装)。
安装 Eleventy
@11ty/eleventy
已经发布到 npm 上了 ,我们可以通过运行以下命令来安装并保写入到项目的 package.json
文件中:
npm install @11ty/eleventy
pnpm install @11ty/eleventy
你也可以 将 Eleventy 安装到全局环境 ,但最推荐的还是上面说的安装到项目本地并写入 package.json
文件。
Step 3 运行 Eleventy
npx @11ty/eleventy
We can use the npx
command (also provided by Node.js) to run our local project's version of Eleventy.
下面是运行 Eleventy 后命令行中输出的内容:
[11ty] Wrote 0 files in 0.03 seconds (v3.0.0)
如果你在输出的内容中看到 (v3.0.0)
字样,说明你使用的是最新版本的 Eleventy。不过,Eleventy 此时并没有处理任何文件!这是意料之中的,因为我们的目录下是空的,没有任何模板文件。
Step 4 创建模板文件
模板(template) 是以 Markdown、HTML、Liquid、Nunjucks 等格式 编写的文件,用于存储内容。Eleventy 在构建网站时将这些文件转换为页面。
让我们运行以下两条命令来创建两个新的模板文件。
echo '<!doctype html><title>Page title</title><p>Hi</p>' > index.html
echo '# Heading' > README.md
echo '<!doctype html><title>Page title</title><p>Hi</p>' | out-file -encoding utf8 'index.html'
echo '# Heading' | out-file -encoding utf8 'README.md'
If the out-file
command is not available in your Windows Terminal window (it’s PowerShell specific), use the Cross Platform method instead.
npx @11ty/create index.html "<!doctype html><title>Page title</title><p>Hi</p>"
npx @11ty/create README.md "# Heading"
Learn more about @11ty/create
(requires Node.js 18 or newer).
你也可以使用任何文本编辑器来创建这些文件,只需确保将这些文件保存到项目目录下即可,并且设置正确的文件扩展名。
创建好上述 HTML 模板和 Markdown 模板之后,我们再次通过以下命令来运行 Eleventy:
输出结果如下所示:
[11ty] Writing _site/README/index.html from ./README.md (liquid)
[11ty] Writing _site/index.html from ./index.html (liquid)
[11ty] Wrote 2 files in 0.04 seconds (v3.0.0)
我们已将当前目录下的两个模板编译并输出到 _site
(默认)目录下了。
Step 5 检查一下模板的输出吧
使用 --serve
参数启动一个支持热重载的本地服务器。
npx @11ty/eleventy --serve
pnpm exec eleventy --serve
yarn exec eleventy --serve
你的命令行将会输出如下信息:
[11ty] Writing _site/index.html from ./index.html (liquid)
[11ty] Writing _site/README/index.html from ./README.md (liquid)
[11ty] Wrote 2 files in 0.04 seconds (v3.0.0)
[11ty] Watching…
[11ty] Server at http://localhost:8080/
在浏览器中打开 http://localhost:8080/
或 http://localhost:8080/README/
网址,就能看到你用 Eleventy 构建的网站了!当你修改并保存模板文件时,Eleventy 会自动刷新浏览器并显示修改后的内容!
Step 6 让网站上线(可选步骤)
进入我们的 部署网站 文档,阅读更多关于如何将 Eleventy 项目上线并让所有人都能看到。
Step 7 继续学习
恭喜!你用 Eleventy 制作了一些东西!现在就让再完善一些吧:
- 添加更多内容!在上述教程中,我们使用了 HTML 和 Markdown。 接下来为什么不试试 JavaScript 或 WebC (用于组件) 呢? Nunjucks 和 Liquid 也很流行。也许你想要一个更大的冒险,为什么不 添加自定义的模板格式呢?。
- 使用 布局文件,这样就不必在每个模板上重复相同的内容了。
- 添加 配置文件 以解锁 Eleventy 的高级功能!
- 为你的项目添加 CSS、JavaScript 或网络字体 。
- 了解更多关于 Eleventy 命令行参数的信息。
- 也许你想在项目中 使用第三方提供的 API ?
教程和项目模板
对于想要 创建博客 的用户,您可以学习如何 从零开始 (了解工作原理) 或者使用我们官方提供的 博客项目模板 (帮你更快上手并运行):
你也可以从以下众多 项目模板 中挑选一个,或者阅读由社区提供的优秀 教程 (下面列出部分精选教程):
更多来自社区的资源
×80 resources via 11tybundle.dev curated by Bob Monsour.
Expand to see 75 more resources.
- Curso Eleventy (Spanish video) — Jon Mircha (2024)
- Eleventy adoption guide: Overview, examples, and alternatives — Nelson Michael (2024)
- Better 11ty Development with Tooling — Paul Everitt (2024)
- Eleventy website to GitHub Pages with GitHub Actions — Andres Bitrian (2024)
- index.md is a valid Eleventy project — Juha-Matti Santala (2024)
- The "IndieWeb" feels like coming home — Nathaniel Daught (2024)
- My Eleventy site setup — anh (2024)
- CSS { In Real Life } | Eleventy Starter Project Updates — Michelle Barker (2024)
- Top 11 free Eleventy themes for 2024 — Jaimie McMahon (2024)
- Mastering Eleventy Folder Structures: From Default Setups to Real-World Best Practices — S. Amir Mohammad Najafi (2024)
- From Figma to Browser with Eleventy (Part 3) — thoughtbot (2024)
- Introduction to Eleventy, a Modern Static Website Generator — David Eastman (2024)
- Eleventy Resume Builder — Gurpreet Singh (2024)
- A bit of a summary of the build of this site and how it works — Tim Klapdor (2024)
- Eleventy vs. Next.js for static site generation — Nelson Michael (2023)
- Implementing a Figma design in Eleventy (Part 2) — thoughtbot (2023)
- Migrating to Eleventy — Renkon (2023)
- From Figma to Browser with Eleventy (Part 1) — thoughtbot (2023)
- My Neocities workflow: using Eleventy and the CLI to speed up development — Whiona (2023)
- Build your own 11ty starter — Simon Cox (2023)
- i11g - Updating an Immutable Blog — Namaskar (2023)
- Build a Blog with Eleventy (11ty) and Webiny Headless CMS — Maurice King (2023)
- Bookshop 11ty Guide — CloudCannon (2023)
- Eleventy by Example, by Bryan Robinson — Raymond Camden (2023)
- Eleventy (11ty), Vite, Tailwind, and Alpine.js – Rapid static site starter framework — Full Stack Digital (2023)
- Book Release: Eleventy by Example – Learn 11ty with 5 in-depth projects — Bryan Robinson (2023)
- How To Craft a Stylish Static Website with Eleventy (11ty) — Joel Olawanle (2023)
- A Complete Guide to Building a Blog with Eleventy — Raymond Camden (2023)
- Eleventy - Build a Static Site with Backend Data Handling - YouTube — Azul Coding (2023)
- Update to My Eleventy Blog Guide — Raymond Camden (2023)
- Getting started with eleventy — Leonardo Silveira (2023)
- A Beginner's Guide to Eleventy - part two — Jakub Iwanowski (2023)
- A Beginner's Guide to Eleventy - part one — Jakub Iwanowski (2023)
- 23 of the best Eleventy Themes (Starters) for 2023 — David Large (2023)
- An Introductory Guide to Eleventy — Don Hamilton (2023)
- 11 Top Eleventy Blog Themes (Starters) in 2023 — David Large (2022)
- New Eleventy features, a new theme, and full Eleventy support — CloudCannon (2022)
- Eleventy Starter Template Series — Dustin Whisman (2022)
- Building an Eleventy Starter Template Series — Dustin Whisman (2022)
- Eleventy Tutorial - Create an 11ty Static Site — Danial Zahid (2022)
- Getting set up in Eleventy (6 part series) — Mike Neumegen (2022)
- Learn the Eleventy Static Site Generator by Building and Deploying a Portfolio Website — Gerard Hynes (2022)
- Walk with an Eleventy site, before you can run — Amal Ayyash (2022)
- Eleventy Crash Course - YouTube playlist — Jaydan Urwin (2022)
- Let's Learn Eleventy (11 Part Series) — James Midzi (2022)
- Build a Blog With 11ty: Categories - Part 3 — Jeremy Faucher (2022)
- Build a Blog With 11ty: Base - Part 2 — Jeremy Faucher (2022)
- Build a Blog With 11ty: Setup - Part 1 — Jeremy Faucher (2022)
- Setting up Future Projects for Success with Template Repositories — Dustin Whisman (2022)
- Minimum Static Site Setup with Sass — Stephanie Eckles (2022)
- A Guide to Building a Blog in Eleventy — Raymond Camden (2022)
- Build JAMstack-ready sites with Bootstrap and 11ty (Eleventy) — Webpixels (2022)
- 11ty tips I wish I knew from the start — David East (2022)
- Going all in with Jamstack and Eleventy — Tim Kleyersburg (2022)
- Introduction to Eleventy (11ty) ELEVENTY — Keenan Payne (2021)
- Make Eleventy the next thing you learn — Thomas Semmler (2021)
- How I Set Up a Project With Eleventy — Nathan Blaylock (2021)
- Turn static HTML/CSS into a blog with CMS using the JAMStack — Kevin Powell (2021)
- Itsiest, Bitsiest Eleventy Tutorial — Sia Karamalegos (2021)
- A Deep Dive Into Eleventy Static Site Generator — Stephanie Eckles (2021)
- Creating a Fast and Beautiful Portfolio Website using HTML, CSS, Eleventy and Netlify — Ingo Steinke (2021)
- Eleventy in eleven minutes — Lea Rosema (2021)
- Building my personal site with Eleventy — Michael Harley (2020)
- Jamstack 101: Getting Started with Eleventy — Joel Varty (2020)
- Getting started with Eleventy in 11 minutes — Luciano Mammino (2020)
- Let's Learn Eleventy (11ty) - What is Eleventy? — Rares Portan (2020)
- Let’s Learn Eleventy! Boost your Jamstack skills with 11ty — Jason Lengstorf (2020)
- Five Critical Things To Do Before Working With 11ty — Khalid Abuhakmeh (2020)
- Building a website with a static site generator, part 3: Domain, Analytics and Forms — Juha-Matti Santala (2020)
- Building a website with a static site generator, part 2: Eleventy — Juha-Matti Santala (2020)
- Building a website with a static site generator, part 1: Setup — Juha-Matti Santala (2020)
- Eleventy Walkthrough — Reg Hunt (2020)
- Teaching in the open: Eleventy — Jérôme Coupé (2020)
- Let’s Learn Eleventy! — Zach Leatherman (2020)
- Build your own Blog from Scratch using Eleventy — Zach Leatherman (2018)
Getting Started: