Skip to content

Commit

Permalink
feat(app): support base URL (#25)
Browse files Browse the repository at this point in the history
* feat(app): support base url

* ci(blog): example action for building cydonia site

* chore(pkg): bumps version to 0.0.6

* ci(cydonia): use 0.0.6

* ci(cydonia): install 0.0.6 with 0.0.5

* ci(cydonia): use root action

* ci(cache): cache with specifed version

* ci(cydonia): remove docs

* chore(blog): remove base in cydonia.toml

* ci(cydonia): get back base

* chore(app): remove the base implementation

* Revert "chore(app): remove the base implementation"

This reverts commit f4649dc.

* fix(watcher): handle the base path in development server

* chore(blog): update the basic template

* chore(action): use 0.0.7

* docs(README): make readme shorter

* docs(manifest): add repo url
  • Loading branch information
clearloop authored Jan 3, 2024
1 parent 513ad29 commit aed8a49
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 212 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/action.yml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/cydonia.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Cydonia

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

jobs:
deploy:
name: Deploy
runs-on: ubuntu-22.04
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- uses: actions/checkout@v4
- uses: ./
- run: cydonia build blog
- name: Deploy
if: github.event_name != 'pull_request'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./blog/out
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
[package]
name = "cydonia"
version = "0.0.7"
edition = "2021"
authors = [ "clearloop" ]
description = "The static site generator."
documentation = "https://docs.rs/cydonia"
version = "0.0.5"
edition = "2021"
homepage = "https://github.com/clearloop/cydonia"
repository = "https://github.com/clearloop/cydonia.git"
license = "GPL-3.0-only"

[dependencies]
anyhow = "1.0.77"
anyhow = "1.0.79"
chrono = { version = "0.4.31", features = [ "serde" ] }
colored = "2.1.0"
etc = "0.1.18"
handlebars = { version = "5.0.0", features = [ "dir_source", "rust-embed" ] }
pulldown-cmark = { version = "0.9.3", default-features = false }
rust-embed = "8.2.0"
serde = { version = "1.0.193", features = [ "derive" ] }
serde_json = "1.0.108"
serde_yaml = "0.9.29"
serde = { version = "1.0.194", features = [ "derive" ] }
serde_json = "1.0.110"
serde_yaml = "0.9.30"
toml = "0.8.8"
tracing = "0.1.40"

Expand All @@ -29,9 +31,8 @@ warp = { version = "0.3.6", optional = true }
futures = { version = "0.3.30", optional = true }
async-lock = { version = "3.2.0", optional = true }


[build-dependencies]
anyhow = "1.0.77"
anyhow = "1.0.79"
which = "5.0.0"

[features]
Expand Down
40 changes: 33 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
## Cydonia
# Cydonia

[![cydonia][version-badge]][version-link]
[![ci][ci-badge]][ci-link]

## Usage

```bash
cargo install cydonia
cydonia init blog
cydonia serve blog
```

For the minimal directory layout:
The minimal directory layout is like below, see [cydonia.toml](./blog/cydonia.toml)
for the full configuration.

```
my-blog
Expand All @@ -18,16 +21,39 @@ my-blog
└── 2024-01-01-hello-world.md
```

see [blog/cydonia.toml][cydonia-toml] for the full configuration of
`cydonia.toml`, [.github/workflows/action.yml][action-yml] for configuring
github actions .
## Github Action

```yaml
name: Cydonia

on:
push:
branches: [main]

jobs:
deploy:
name: Deploy
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: clearloop/cydonia@0.0.7

- name: Build the site
run: cydonia build blog

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./blog/out
```
## LICENSE
GPL-3.0-only
[action-yml]: .github/workflows/action.yml
[cydonia-toml]: blog/cydonia.toml
[version-badge]: https://img.shields.io/crates/v/cydonia
[version-link]: https://docs.rs/cydonia
[ci-badge]: https://img.shields.io/github/actions/workflow/status/clearloop/cydonia/main.yml
Expand Down
11 changes: 8 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ branding:

inputs:
version:
description: "The version of cydonia to install"
required: true
default: "0.0.5"
description: The version of cydonia to install
default: "0.0.7"

runs:
using: composite
Expand All @@ -24,7 +24,12 @@ runs:
shell: bash
run: |
BIN=~/.cargo/bin/cydonia
if [ ! -f $BIN ]; then
if [ -f $BIN ]; then
VERSION=$($BIN --version)
if [ "$VERSION" -nq ${{ inputs.version }} ]; then
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
Expand Down
23 changes: 8 additions & 15 deletions blog/cydonia.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# my-blog/cydonia.toml
title = "Cydonia" # The title of the site.
title = "Cydonia" # The title of the site.

# Default values of the optional fields.
# --------------------------------------

favicon = "favicon.svg" # The path to the favicon.
out = "out" # The path to the output directory.
posts = "posts" # The path to the posts.
public = "public" # The path to the public directory.
templates = "templates" # The path to the templates.

# Theme could also be a folder:
#
# - [theme]
# - index.css (required)
# - post.css (required)
# - theme.css (optional)
theme = "theme"
base = ""
favicon = "favicon.svg" # The path to the favicon.
out = "out" # The path to the output directory.
posts = "posts" # The path to the posts.
public = "public" # The path to the public directory.
templates = "templates" # The path to the templates.
theme = "theme/theme.css" # The path to the theme.css
18 changes: 7 additions & 11 deletions blog/templates/head.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,24 @@
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="{{tab}}">
<meta name="twitter:image" content="https://github.com/clearloop/cydonia/releases/download/v0.0.2-pre/cydonia.svg">
<meta name="twitter:description" content="{{ description }}">
<!-- <meta name="twitter:site" content="@cydonia"> -->
<!-- <meta name="twitter:creator" content="@cydonia"> -->
<!-- <meta name="twitter:description" content="{{ tab }}"> -->

<!-- theme -->
<link rel="stylesheet" href="{{ base }}theme.css">

<!-- favicon -->
{{#if favicon}}
<link rel="shortcut icon" href="{{ favicon }}">
{{/if}}

<!-- styles for index -->
{{#if posts}}
<link rel="stylesheet" href="/index.css">
<link rel="shortcut icon" href="{{ base }}{{ favicon }}">
{{/if}}

<!-- styles for post -->
{{#if post}}
<link rel="stylesheet" href="/highlight.css">
<link rel="stylesheet" href="/post.css">
<script src="/highlight.js" defer></script>
<link rel="stylesheet" href="{{ base }}highlight.css">
<script src="{{ base }}highlight.js" defer></script>
{{/if}}


<!-- livereload -->
{{#if livereload}}
<script>
Expand Down
17 changes: 6 additions & 11 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ impl<'app> App<'app> {
pub fn data(&self, mut value: Value) -> Result<Value> {
let mut map = Map::<String, Value>::new();
map.insert("title".into(), self.manifest.title.clone().into());
map.insert("base".into(), self.manifest.base.clone().into());
map.insert(
"description".into(),
self.manifest.description.clone().into(),
);

if self.livereload {
map.insert("livereload".into(), LIVERELOAD_ENDPOINT.into());
Expand Down Expand Up @@ -181,17 +186,7 @@ impl<'app> App<'app> {

/// Write theme to the output directory.
pub fn render_theme(&self) -> Result<()> {
self.manifest.theme()?.write(&self.manifest.out)?;

// Override highlight.{css, js} if exist
for hl in ["highlight.js", "highlight.css"] {
let path = self.manifest.theme.join(hl);
if path.exists() {
fs::copy(path, self.manifest.out.join(hl))?;
}
}

Ok(())
self.manifest.write_theme(&self.manifest.out)
}

/// Render a template.
Expand Down
Loading

0 comments on commit aed8a49

Please sign in to comment.