Skip to content

Commit

Permalink
finish v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wendevlin committed May 29, 2024
1 parent 5fe6ed2 commit 27e5b0e
Show file tree
Hide file tree
Showing 31 changed files with 73 additions and 153 deletions.
6 changes: 6 additions & 0 deletions homedocs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<!-- https://developers.home-assistant.io/docs/add-ons/presentation#keeping-a-changelog -->

## 2.0.0

- **BREAKING** The /config/homedocs directory doesn't need the content/docs, assets and files folder anymore. All content is now directly in the /config/homedocs folder.
- Homedocs rewritten without astro. Uses now an elysia webserver and markdown-it for rendering markdown.
- **BREAKING** Config changed and internal ports changed. I recommend to uninstall and reinstall the addon. Your markdown data will be kept in the home assistant config folder.

## 1.0.9

- Fix webserver to use correct base url
Expand Down
3 changes: 3 additions & 0 deletions homedocs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ RUN npm install -g bun
COPY server /server
WORKDIR /server

RUN bun install
RUN bun run build

# copy and setup run script
COPY run.sh /
RUN chmod a+x /run.sh
Expand Down
34 changes: 7 additions & 27 deletions homedocs/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
# Homedocs

With this home assistant addon you can easily create a documentation site for your home or something else.
It uses Starlight from astro under the hood.

__Why homedocs__
- Create a documentation site for your home and everything else
- Auth with home assistant
- Fast to create with markdown

__Why starlight?__

- Very good docs layout
- markdown and MDX support
- integrated search
- images are automatically optimized
- mobile optimized
- dark mode

__How I use it__:

I document stuff that I don't need very often, for example a yearly maintainance of the heating.
Moreover I printed QR codes on some devices, that you can fast access the documentation.
In my docs I also store all manual files, so I have everything in one place.

I have multiple documentation sites for:
- garden
Expand All @@ -41,30 +32,19 @@ I have multiple documentation sites for:
3. the addon creates a folder called `homedocs` in your config folder
4. the addon copies some sample data to this folder
5. edit the markdown files in the `homedocs` folder
- in the `content/docs` folder you can write your documentation
- all images should be placed in the `assets` folder
- the will be automatically optimized by astro
6. The addon will recognize the changes and build the site after a give timeout (60 seconds is default)
- the timeout is needed because the build takes some time and can just runs once in parallel.
6. The addon will recognize the changes and build the site
7. open the webui to see your beautiful documentation
8. (optional) you can open it outside of your home assistant if you have the port configured

## Troubleshooting

### Build is not triggered

I had sometimes the issue that the build wasn't triggert, if this happens you can restart your addon, then the build will be triggert on startup.

## Check the logs!

If your made a mistake in your markdown files the build will fail, check the logs for more information. Starlight will give you a hint on what went wrong.
You won't see the error in the browser, it will still display the last version.

## Roadmap

- [ ] Build information in frontend
- I could add custom web path for build information or it will be displayed on every page as some kind of overlay
- [ ] Themes
- Starlight has a built in theme feature, I could provide some predefined themes to select from and the possibility to create custom themes
- Moreover I could get the home assistant theme and use this base colors
- [ ] hot reload
- Starlight is working on SSR, maybe it is then possible to have hot reload instead of the full build
- [ ] Image optimization
- [ ] More efficient build
- [ ] Integrated search
- [ ] Table of contents
11 changes: 0 additions & 11 deletions homedocs/archive/docs/guides/example.md

This file was deleted.

37 changes: 0 additions & 37 deletions homedocs/archive/docs/index.mdx

This file was deleted.

19 changes: 0 additions & 19 deletions homedocs/archive/docs/reference/example.md

This file was deleted.

4 changes: 2 additions & 2 deletions homedocs/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Homedocs

Check warning on line 1 in homedocs/config.yaml

View workflow job for this annotation

GitHub Actions / Lint add-on homedocs

'map' contains the 'config' folder, which has been replaced by 'homeassistant_config'. See: https://developers.home-assistant.io/blog/2023/11/06/public-addon-config
description: Document stuff with Markdown
version: "2.0.0-beta.1"
version: "2.0.0"
slug: homedocs
init: false
url: https://github.com/masterwendu/homeassistant-addons/tree/main/homedocs
Expand All @@ -21,4 +21,4 @@ ports_description:
3000/tcp: Web interface (Not required for Ingress)
panel_icon: mdi:text-box-outline
panel_admin: false
image: "ghcr.io/masterwendu/{arch}-addon-homedocs"
# image: "ghcr.io/masterwendu/{arch}-addon-homedocs"
4 changes: 2 additions & 2 deletions homedocs/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ -z "$(ls -A /config/homedocs)" ]; then
echo "created /config/homedocs directory."

# copy the example contents of the "/starlight/src/content/docs" directory to the "/config/homedocs" directory.
cp -r /server/docs /config/homedocs
cp -r /server/docs/* /config/homedocs
echo "copied example content to /config/homedocs."
else
echo "/config/homedocs is not empty, skipping copy example content."
Expand All @@ -19,4 +19,4 @@ fi
# BUILD_TIMEOUT_IN_SECONDS=$(bashio::config 'buildTimeoutInSeconds')

# start the webserver
NODE_ENV=production DOCS_BASE_PATH=/config/homedocs bun run start:production
DOCS_BASE_PATH=/config/homedocs bun run start:production
Binary file modified homedocs/server/bun.lockb
Binary file not shown.
7 changes: 7 additions & 0 deletions homedocs/server/docs/Downloads/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
If you want to save for example some manuals you can create download links with the HTML syntax:

```html
<a href="../files/sample.pdf" download>here</a>
```

Download the file <a href="../files/sample.pdf" download>here</a>
7 changes: 7 additions & 0 deletions homedocs/server/docs/Folder/hierarchy/file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# File in folder

I am a markdown file:

- 1. One
- 2. Two
- 3. Three
8 changes: 8 additions & 0 deletions homedocs/server/docs/Folder/hierarchy/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---

title: Subfolder

---


This is a index file in a subfolder of a folder, with a defined title so the subfolder name will be overwritten.
5 changes: 0 additions & 5 deletions homedocs/server/docs/amazing/spiderman.md

This file was deleted.

1 change: 0 additions & 1 deletion homedocs/server/docs/amazing/venom/description.md

This file was deleted.

3 changes: 0 additions & 3 deletions homedocs/server/docs/amazing/venom/index.md

This file was deleted.

Binary file added homedocs/server/docs/files/sample.pdf
Binary file not shown.
7 changes: 0 additions & 7 deletions homedocs/server/docs/hellooo.md

This file was deleted.

Binary file added homedocs/server/docs/images/Home-Docs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions homedocs/server/docs/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
---
title: Test
uga: Affe
title: Welcome to Homedocs
---

# this is the main woodhome
![](./images/Home-Docs.png)

hallloo oida?
## Congrats on setting up a new Homedocs project!

Your documentation files are located in the homedocs folder inside your home assistant configuration.

## Get started writing your homedocs!

![](./images/documentation.gif)
11 changes: 0 additions & 11 deletions homedocs/server/docs/my/index.md

This file was deleted.

1 change: 0 additions & 1 deletion homedocs/server/docs/my/uga/affe.md

This file was deleted.

1 change: 0 additions & 1 deletion homedocs/server/docs/test/test/test/test/index.md

This file was deleted.

Empty file.
1 change: 0 additions & 1 deletion homedocs/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"chokidar": "3.6.0",
"elysia": "1.0.22",
"glob": "10.4.1",
"logestic": "1.2.0",
"markdown-it": "14.1.0",
"markdown-it-emoji": "3.0.0",
"zod": "3.23.8"
Expand Down
13 changes: 7 additions & 6 deletions homedocs/server/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { build } from "bun"
// import { build } from "bun"
import { buildCss } from "./tailwind"

// build css with tailwind and daisyui
Expand All @@ -7,10 +7,11 @@ await buildCss()
console.log('CSS build finished ✓')

// build the server
await Bun.build({
entrypoints: ['./src/index.ts'],
outdir: './dist',
target: 'bun',
})
// TODO use optimized bun build
// await Bun.build({
// entrypoints: ['./src/index.ts'],
// outdir: './dist',
// target: 'bun',
// })

console.log('Server build finished ✓')
4 changes: 2 additions & 2 deletions homedocs/server/src/htmlBuilder/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export const generateNavForFolder = async (
)
if (index > -1) {
const indexChild = children[index]
// const { title, content } = await parseFile(`${folder}/${fileOrFolder}/index.md`, fileOrFolder)

const path = indexChild.path!

children.splice(index, 1)

level.push({
title: indexChild.title ?? fileOrFolder,
title:
indexChild.title !== 'index' ? indexChild.title : fileOrFolder,
path,
children,
htmlContent: indexChild.htmlContent,
Expand Down
3 changes: 1 addition & 2 deletions homedocs/server/src/markdown/frontMatterPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const frontMatterPlugin = (md: MarkdownIt) => {
// while pos <= 3
let start = state.bMarks[startLine] + state.tShift[startLine]
let max = state.eMarks[startLine]
let start_content: number
let start_content = 0
let pos: number
for (pos = start + 1; pos <= max; pos++) {
if (marker_str[(pos - start) % marker_len] !== state.src[pos]) {
Expand Down Expand Up @@ -155,7 +155,6 @@ export const frontMatterPlugin = (md: MarkdownIt) => {
for (const line of token.meta.split('\n')) {
const [key = '', value = ''] = line.split(':')
if (key && value) {
console.log('frontmatter', key, value)
frontMatterObject[key.trim()] = value.trim()
}
}
Expand Down
3 changes: 1 addition & 2 deletions homedocs/server/src/markdown/markdownParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface MarkdownIt extends Markdownit {

const md = markdownit({
linkify: true,
html: true,
})
.use(emoji)
.use(frontMatterPlugin) as MarkdownIt
Expand Down Expand Up @@ -39,5 +40,3 @@ export const parseFile = async (filePath: string, filename: string) => {
content: htmlContent,
}
}

await parseFile('./docs/my/index.md', 'my')
2 changes: 1 addition & 1 deletion homedocs/server/src/templates/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default (
) => (
<html lang="en">
<head>
<title>{title}</title>
<title>Homedocs</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="./main.css" />
Expand Down
2 changes: 1 addition & 1 deletion homedocs/server/src/templates/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const subNavigation = (
{path === undefined ? (
<span class="hover:bg-nav dark:hover:bg-nav-dark hover:cursor-default">
<svg
class="w-4 -ml-1 -mr-1"
class="w-4 -ml-1 -mr-1 dark:fill-white"
aria-hidden="true"
viewBox="-43.52 -43.52 599.04 599.04"
>
Expand Down
Loading

0 comments on commit 27e5b0e

Please sign in to comment.