Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit cc36c73

Browse files
committed
Merge branch 'master' of github.com:Yukuro/hugo-theme-shell
2 parents 89aa746 + f03c45e commit cc36c73

File tree

1 file changed

+163
-0
lines changed

1 file changed

+163
-0
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# Customize the terminal as you like
2+
3+
## Note
4+
This document explains how to customize the terminal, but it is a temporary solution.\
5+
It is subject to change in future updates.
6+
7+
## 0. Directory structure
8+
The Hugo configuration to be customized looks like this.\
9+
This is the file structure of the hugo-theme-shell [READMD.md](https://github.com/Yukuro/hugo-theme-shell/blob/master/README.md#installation) with all the steps completed.
10+
```bash
11+
$hugo new site mysite
12+
$cd mysite
13+
$tree .
14+
.
15+
├── archetypes
16+
│   └── default.md
17+
├── config.toml
18+
├── content
19+
├── data
20+
├── layouts
21+
├── static
22+
└── themes
23+
  └── hugo-theme-shell
24+
```
25+
26+
## 1. Copy some files to layouts
27+
Hugo 0.42 or later has a feature that allows you to customize the theme without editing the original theme.
28+
29+
In order to customize the terminal, you need to edit the following files
30+
- `hugo-theme-shell/layouts/index.html`
31+
- `hugo-theme-shell/layouts/partials/typeIndex.html`
32+
33+
Copy it to `mysite/layouts`
34+
```bash
35+
$mkdir -p ./layouts/partials
36+
$cp ./themes/hugo-theme-shell/layouts/index.html
37+
$cp ./themes/hugo-theme-shell/partials/typeIndex.html
38+
```
39+
40+
## 2. Edit file
41+
In `hugo-theme-shell`, the contents of `config.toml` are passed to `typeIndex.html` according to the [Hugo Template](https://gohugo.io/templates/) written in `index.html`
42+
43+
From here, we will edit the copied file, but the task will vary depending on what you want to do.
44+
- If you want to change only the order of the commands
45+
- go to chapter 2-A
46+
- If you want to change the order of the commands and change the display of the commands
47+
- go to chapter 2-B
48+
49+
## 2-A Change only the order of the commands
50+
Here we want to add `[userName]@[pcName]:~/[workDir]$ cat [profile]` between the last line of the teminal and the line before it.
51+
52+
In `typeIndex.html`\
53+
The collection of `span` tags at the beginning is the root of the order of the commands.\
54+
Thus, if you want to add it between the last line and the line before it, add `<span id="ps1_05"></span> <span id="cat2"></span> <br>` at that position.
55+
```html
56+
<span id="ps1_01"></span> <span id="cd"></span> <br>
57+
<span id="ps1_02"></span> <span id="cat"></span> <br>
58+
<span id="std_out_01"></span> <br>
59+
<span id="ps1_03"></span> <span id="tree"></span> <br>
60+
<span id="std_out_02"></span> <br>
61+
+++ <span id="ps1_05"></span> <span id="cat2"></span> <br>
62+
<span id="ps1_04"></span> <br>
63+
```
64+
The id of the `span` tag must be unique.
65+
66+
The javascript in the second half of `typeIndex.html` uses `async/await` to control the typing effect.\
67+
In particular, `typeeffect` is associated with the edited `span` tag, so you need to insert the code in the correct order.
68+
```javascript
69+
const typeeffetct = async () => {
70+
await typewriter("{{ .env }}", "ps1_01", ps1Delay); await typewriter("{{ .cd }}", "cd", commandDelay);
71+
await typewriter("{{ .envWithDir }}", "ps1_02", ps1Delay); await typewriter("{{ .cat }}", "cat", commandDelay);
72+
await typewriter("{{ .description }}", "std_out_01", stdoutDelay);
73+
await typewriter("{{ .envWithDir }}", "ps1_03", ps1Delay); await typewriter("{{ .tree }}", "tree", commandDelay);
74+
await typewriter("{{ .leaf }}", "std_out_02", stdoutDelay);
75+
+++ await typewriter("{{ .envWithDir }}", "ps1_05", ps1Delay); await typewriter("{{ .cat }}", "cat2", commandDelay);
76+
await typewriter("{{ .envWithDir }}", "ps1_04", ps1Delay);
77+
return;
78+
}
79+
```
80+
81+
## 2-B Change the order of the commands and change the display of the commands
82+
If you want to change the contents of the command, you need to edit `config.toml` and `index.html` additionally in addition to the steps in 2-A.
83+
84+
In this example, after adding `[userName]@[pcName]:~/[workDir]$ cat [profile2]` to the last line of the terminal, we want to display the contents of `[profile2]` (`[description2]`)
85+
86+
In `config.toml`\
87+
In `config.toml`, under `[Params.Terminal]`, set the content you want to display and the name of the property that defines it.\
88+
In this example, we will set `profile2` and `description2`.
89+
```toml
90+
pcName = "PC"
91+
workDir = "mydi"
92+
profile = "profile.log"
93+
+++ profile2 = "profile_other.log"
94+
```
95+
96+
```toml
97+
contentDelay = 0 # content speed : content in .md file
98+
99+
description = """
100+
Hi I am Jane Doe!
101+
Nice to meet you!
102+
Wow!
103+
"""
104+
105+
+++ description2 = """
106+
+++ Hi I like apple.
107+
+++ """
108+
```
109+
110+
In `index.html`\
111+
Takes the property name and its contents from `config.toml` and passes it to `typeIndex.html`.\
112+
Here, we create the variables `cat2` and `description2` and pass them to typeIndex.html through `partial`.
113+
```html
114+
{{ $stdoutDelay := $.Site.Params.Terminal.stdoutDelay }}
115+
{{ $commandDelay := $.Site.Params.Terminal.commandDelay }}
116+
117+
+++ {{ $cat2 := printf "<span id=terminal>cat %s</span>" .Site.Params.Terminal.profile2 | safeHTML }}
118+
+++ {{ $description2 := printf "<span id='terminal'>%s</span>" .Site.Params.Terminal.description2 | safeHTML}}
119+
+++ {{ partial "partials/typeIndex.html" (dict "context" . "env" $env "cd" $cd "envWithDir" $envWithDir "cat" $cat "description" $description "tree" $tree "leaf" $leaf "ps1delay" $ps1Delay "stdoutdelay" $stdoutDelay "commanddelay" $commandDelay "cat2" $cat2 "description2" $description2) }}
120+
```
121+
122+
In `typeIndex.html`\
123+
Basically, what you need to do is the same as in step 2-A.\
124+
Edit the HTML part that controls the display order and the javascript that controls the typing animation.
125+
```html
126+
<span id="ps1_01"></span> <span id="cd"></span> <br>
127+
<span id="ps1_02"></span> <span id="cat"></span> <br>
128+
<span id="std_out_01"></span> <br>
129+
<span id="ps1_03"></span> <span id="tree"></span> <br>
130+
<span id="std_out_02"></span> <br>
131+
<span id="ps1_04"></span> <br>
132+
+++ <span id="ps1_05"></span> <span id="cat2"></span> <br>
133+
+++ <span id="std_out_03"></span> <br>
134+
```
135+
136+
```javascript
137+
const typeeffetct = async () => {
138+
await typewriter("{{ .env }}", "ps1_01", ps1Delay); await typewriter("{{ .cd }}", "cd", commandDelay);
139+
await typewriter("{{ .envWithDir }}", "ps1_02", ps1Delay); await typewriter("{{ .cat }}", "cat", commandDelay);
140+
await typewriter("{{ .description }}", "std_out_01", stdoutDelay);
141+
await typewriter("{{ .envWithDir }}", "ps1_03", ps1Delay); await typewriter("{{ .tree }}", "tree", commandDelay);
142+
await typewriter("{{ .leaf }}", "std_out_02", stdoutDelay);
143+
await typewriter("{{ .envWithDir }}", "ps1_04", ps1Delay);
144+
+++ await typewriter("{{ .envWithDir }}", "ps1_05", ps1Delay); await typewriter("{{ .cat2 }}", "cat2", commandDelay);
145+
+++ await typewriter("{{ .description2 }}", "std_out_03", stdoutDelay);
146+
return;
147+
}
148+
```
149+
150+
## Tips
151+
Many of the variables in `typeIndex.html` (`envWithDir, cat ... `) are defined in `index.html`, and have the following meaning
152+
| Variable name | Relation to config.toml |
153+
| ---- | ---- |
154+
| env | `[userName]@[pcName]:~/` |
155+
| envWithDir | `[userName]@[pcName]:~/[workDir]` |
156+
| cd | `cd [workDir]` |
157+
| cat | `cat [profile]` |
158+
| description | `description` |
159+
| tree | `tree [folderName]` |
160+
| leaf | `[folderName] etc` |
161+
| ps1delay | `display speed of [userName]@[pcName]:~/` |
162+
| stdoutdelay | `display speed of [description], [leaf]` |
163+
| commanddelay | `display speed of command(cd [workdir] / cat [profile])` |

0 commit comments

Comments
 (0)