惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
月光博客
月光博客
人人都是产品经理
人人都是产品经理
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
Vercel News
Vercel News
MyScale Blog
MyScale Blog
爱范儿
爱范儿
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
H
Help Net Security
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LangChain Blog
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
宝玉的分享
宝玉的分享
博客园 - 聂微东
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
博客园 - 叶小钗
D
Docker

Deno

Deno 2.8 | Deno Claw Patrol: an open-source security firewall for agents | Deno Fresh 2.3: Zero JS by default, View Transitions, and Temporal support | Deno Deno 2.7: Temporal API, Windows ARM, and npm overrides | Deno Build a dinosaur runner game with Deno, pt. 6 | Deno Build a dinosaur runner game with Deno, pt. 5 | Deno Deno Deploy is Generally Available | Deno Introducing Deno Sandbox | Deno Build a dinosaur runner game with Deno, pt. 4 | Deno Build a dinosaur runner game with Deno, pt. 3 | Deno Build a dinosaur runner game with Deno, pt. 2 | Deno React / Next.js Denial-of-Service Vulnerability: Deno Deploy users protected | Deno Deno 2.6: dx is the new npx | Deno Build a dinosaur runner game with Deno, pt. 1 | Deno React Server Functions / Next.js Vulnerability: Deno Deploy users protected | Deno My highlights from the new Deno Deploy | Deno Deno's Other Open Source Projects | Deno How Deno protects against npm exploits | Deno Help Us Raise $200k to Free JavaScript from Oracle | Deno Deno 2.5: Permissions in the config file | Deno Fresh 2.0 Graduates to Beta, Adds Vite Support | Deno Deno 2.4: deno bundle is back | Deno JavaScript™ Trademark Update | Deno What's coming to JavaScript | Deno A brief history of JavaScript | Deno Reports of Deno's Demise Have Been Greatly Exaggerated | Deno An Update on Fresh | Deno How Plaid migrated 100 services to a new database platform 5x faster with Deno | Deno Deno 2.3: Improved deno compile, local npm packages, and more | Deno Add JSR packages with pnpm and Yarn | Deno
How to setup a blog with Hugo and Deno Deploy | Deno
Andy Jiang · 2022-04-27 · via Deno

You might be surprised that a static site generator written in Go can be published on Deno Deploy.

Since Deno embraces web standards, the runtime can fetch and execute external code. For example, Deno can run a simple HTTP file server through an import via URL with zero additional config or compile steps. And since this simply serves static files, it doesn’t matter how the static site is generated.

In this example, we’ll show you how to setup and deploy a static site with Hugo and Deno Deploy in minutes.

Note that we selected Hugo because it’s a popular static site generator written in Go with a fast build time (less than 1 ms per page). However, any static site generator can work with Deno Deploy.

Setup Hugo

Hugo already has some fantastic resources on getting started, but here is a short summary.

Install Hugo

On MacOS, you can use homebrew or macports to install Hugo. For a more comprehensive list on installing Hugo, see their install guide.

Create a new site and install a theme

You can use the hugo command to create a new site:

$ hugo new site hugo-on-deno-deploy

This creates a new directory “hugo-on-deno-deploy” that contains the project. Navigate into that folder to install a theme.

Hugo allows you to use git submodules to install a theme. Let’s install the ananke theme and add it to the config.toml file:

$ git init
$ git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
$ echo theme = \"ananke\" >> config.toml

To explore other themes, check out Hugo’s list of themes.

Add a blog post

Again, we can use hugo to create a blog post. The following will create a directory “posts” and, in it, create a new file named “my-first-post.md”, all under the directory “content”.

$ hugo new posts/my-first-post.md

Your newly created markdown file will automatically contain some frontmatter with an empty body:

---
title: "My First Post"
date: 2022-03-21T17:55:41-07:00
draft: true
---

Start the local server and check it out!

Note the -D flag will show all posts where draft: true.

Hugo blog running locally

Setup Git/Github

GitHub is a critical part of using CI/CD to deploy to Deno Deploy. To set it up, we simply create a GitHub repository and add the project directory.

First, create a repo in Github:

Creating a repo in GitHub

Grab the remote URL, add it to your local git remote, and push to GitHub.

$ git remote add origin git@github.com:lambtron/hugo-on-deno-deploy.git
$ git add .
$ git commit -am “first commit”
$ git push origin main

Your Hugo blog should now be a repository on GitHub.

Setup Deno Deploy

Deno Deploy, our distributed TypeScript and JavaScript runtime on the edge, provides first class GitHub support, which means automatic deployments that fit into your workflow.

First, go to Deno Deploy and click “Sign Up”. This will ask you to connect your GitHub account.

Then, create a new project:

Creating a new Deno Deploy project

Select “Deploy from GitHub”, link the repository, and use the production branch. For deployment mode, select “GitHub Actions”, because we want to use GitHub Actions to first build the site using Hugo and then deploy it to Deno Deploy:

Setting up GitHub Actions with Deno Deploy

When you click “Link”, there will be a confirmation message, as well as sample yaml to add to your GitHub action:

Confirming Git integration with Deno Deploy

We’ll use the sample yaml as a starting point for creating our GitHub Action.

Setup Github Actions

Github Actions are a simple way to automate your deployment workflows. In our example, GitHub Actions will clone the repo onto an ubuntu image, install hugo, build the site, then deploy it to Deno Deploy.

You can create a GitHub Action workflow from the UI, or you can simply add a .github/workflows/main.yml file and commit it:

name: Deploy to Deno Deploy


on:
  
  push:
    branches: [main]
  pull_request:
    branches: [main]

  
  workflow_dispatch:



jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    permissions:
      id-token: write 
      contents: read 

    steps:
      - name: Clone repository
        uses: actions/checkout@v2
        with:
          submodules: true 
          fetch-depth: 0 

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: "latest"

      - name: Build site
        run: hugo --minify

      - name: Deploy to Deno Deploy
        uses: denoland/deployctl@v1
        with:
          project: hugo-on-deno-deploy 
          entrypoint: https://deno.land/std@0.140.0/http/file_server.ts
          root: public 

The final action of the workflow uses deployctl, a command line tool for Deno Deploy. For the entry point, we’ll use Deno’s std lib fileserver. Note that we don’t need to “download” the file server–simply providing the URL address of the raw TypeScript file is enough for Deno Deploy to run the server.

Now, let’s try a sample deployment. Commit to main branch (or merge a pull request onto main branch) to trigger the GitHub Action.

After the GitHub Action runs successfully, click “View” in your project on Deno Deploy:

The Hugo blog is now live on Deno Deploy

Publish a Blog Post

Now that we have continuous deployment setup with GitHub and Deno Deploy, let’s publish our first blog post.

First step is to use hugo to create a blog post.

$ hugo new posts/my-second-post.md

Add some content to the new markdown file and remove draft: true from the frontmatter.

---
title: "My Second Post"
date: 2022-03-24T09:58:34-07:00
---

This is my second post!

Preview your site locally with hugo server. When you’re happy with the post, commit the changes to your main branch. Finally, after the GitHub Actions successfully deploys:

Publishing the second post on Deno Deploy

What’s next?

Using Hugo with Deno Deploy is one of the simplest ways to get a blog up and deployed globally on the edge. Additionally, the continuous deployment setup makes publishing blog posts easy, so you can focus on the content.

This example also shows that your static site generator doesn’t need to be written in JavaScript or TypeScript to run on Deno Deploy. Any static site generator can be used, so long as HTML files can be statically served.

View the source code or play with the demo.

Want to share what you’ve deployed on Deno Deploy or have questions? Come say hi on our Discord.