SitePipe 使用教程

SitePipe 使用教程

SitePipe Yet another static site generator - non-opinionated, value-level. Less magic == easier to understand SitePipe 项目地址: https://gitcode.com/gh_mirrors/si/SitePipe

1. 项目目录结构及介绍

SitePipe 是一个简单的静态网站生成器,适用于创建博客、个人网站等。项目的主要目录结构如下:

site/
├── templates/        # 存放模板文件
│   ├── post.html
│   └── index.html
└── posts/            # 存放 Markdown 格式的文章
    └── article.md
  • templates/ 目录:包含了网站的模板文件,index.html 是网站的首页模板,post.html 是文章页面的模板。
  • posts/ 目录:包含了所有的文章内容,以 Markdown 格式存储。

2. 项目的启动文件介绍

项目的启动文件是位于项目根目录下的 Main.hs。这个文件负责初始化和运行 SitePipe。

module Main where

import SitePipe

main :: IO ()
main =
  site $
    do
      -- 加载 posts 目录下的所有 Markdown 文章
      posts <- resourceLoader markdownReader ["posts/*.md"]

      -- 创建首页的上下文
      let indexContext :: Value
          indexContext = object ["posts" .= posts, "url" .= "/index.html"]

      -- 通过模板输出首页和文章
      writeTemplate "templates/index.html" [indexContext]
      writeTemplate "templates/post.html" posts

在这个文件中,site 函数是 SitePipe 的入口点,它接受一个 IO 操作,这里是通过 do 表达式组织的几个操作:

  • 使用 resourceLoader 加载 posts/ 目录下的所有 Markdown 文件,并通过 markdownReader 将它们转换为 HTML。
  • 创建一个包含文章列表和首页 URL 的上下文 indexContext
  • 使用 writeTemplate 函数将上下文和文章通过模板输出为 HTML。

3. 项目的配置文件介绍

SitePipe 的配置主要通过 sitepipe.cabalstack.yaml 文件来进行。

  • sitepipe.cabal 文件:这是 Haskell 包的配置文件,它定义了项目的依赖、编译选项和其他元数据。
name:                sitepipe
version:             0.3.0.1
synopsis:            A simple static site generator
description:         SitePipe is a static site generator written in Haskell.
license:             BSD3
author:              Your Name
maintainer:          your.email@example.com
category:            Web
build-type:          Custom
cabal-version:       >=1.10

library
  exposed-modules:   SitePipe
  build-depends:     base >= 4.7 && < 5
                    , pandoc
                    , aeson
                    , filepath
                    , text
                    , containers
                    , mustache
                    , directory
                    , process
  default-language:  Haskell2010
  other-extensions:  OverloadedStrings
  ghc-options:       -Wall
  • stack.yaml 文件:这是 Stack 构建工具的配置文件,它指定了项目的依赖和构建参数。
resolver: lts-15.3
maintainer: your.email@example.com
extra-deps:
- pandoc-2.9.2.1
- aeson-1.5.6.0
- filepath-1.4.2.1
- text-1.2.4.0
- containers-0.6.2.1
- mustache-2.2.1
- directory-1.3.6.0
- process-1.6.13.0

这些配置文件在项目初始化时创建,通常不需要用户修改,除非需要定制特定的功能或者修复依赖问题。

SitePipe Yet another static site generator - non-opinionated, value-level. Less magic == easier to understand SitePipe 项目地址: https://gitcode.com/gh_mirrors/si/SitePipe

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郝钰程Kacey

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值