Skip to content

Commit

Permalink
updated to new content structure
Browse files Browse the repository at this point in the history
  • Loading branch information
wassfila committed May 9, 2024
1 parent b4ce178 commit aeb05bf
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 58 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": "file:///d%3A/Dev/HomeSmartMesh/website/.github/workflows/deploy.yml"
}
}
11 changes: 6 additions & 5 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
//in DEV Mode process.env does not have .env content
import * as dotenv from 'dotenv'
import {join} from 'path'

dotenv.config()
const rootdir = process.cwd()

const outdir = (process.env.OUT_DIR==null)?"dist":process.env.OUT_DIR
const base = (process.env.PUBLIC_BASE==null)?"":process.env.PUBLIC_BASE
const contentdir = "content"
const contentdir = join(rootdir,"content")
const structuredir = join(rootdir,".structure")

const config = {
rootdir: rootdir,
outDir: outdir,
base: base,
content_path: `${rootdir}/${contentdir}`,
content_path: contentdir,
code_path: `${rootdir}/${outdir}/codes`,
plantuml_server: "https://www.plantuml.com/plantuml/svg",
kroki_server: "https://kroki.io",
Expand All @@ -28,11 +30,10 @@ const config = {

config.collect_content = {
rootdir:config.rootdir,
rel_contentdir:contentdir,
contentdir:contentdir,
content_ext:["md"],
assets_ext:["svg","webp","png","jpeg","jpg","xlsx","glb","hdr","ico"],
rel_outdir:".structure",//dist does not persist before build
raw_menu:"menu.yaml",
outdir:structuredir,
out_menu:"public/menu.json",//used by src\layout\client_nav_menu.js
debug:false
}
Expand Down
2 changes: 1 addition & 1 deletion content/3dprinting/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title : 3D Printing
slug: 3dprinting
description: 3D Models for Smart Home, electronics and house utilities
order: 9
order: 5
date: 2021-01-17T00:00:00+00:00
image: ./3dmodels.png
features:
Expand Down
2 changes: 1 addition & 1 deletion content/frameworks/readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title : Frameworks
description: Services, middleware and environments for applications eco-systems
order: 1
order: 3
date: 2020-10-06T08:48:23+00:00
lastmod: 2020-10-06T08:48:23+00:00
---
1 change: 1 addition & 0 deletions content/home/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ date: 2020-10-06T08:48:23+00:00
lastmod: 2021-02-14T08:00:00+00:00
image: /images/floor_temperature.png
toc: false
order: 1
---

```yaml cards
Expand Down
3 changes: 3 additions & 0 deletions content/icons.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- icon: github
align: right
link: https://github.com/HomeSmartMesh/website-astro
2 changes: 1 addition & 1 deletion content/other/readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title : Other
description: Other Miscelaneous projects e.g. Sound processing, Home Robotics and electromechanical smart automation
order: 4
order: 7
date: 2021-03-07T08:00:00+00:00
lastmod: 2021-03-07T08:00:00+00:00
---
5 changes: 5 additions & 0 deletions content/protocols/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Protocols
order: 4
---
protocols page
2 changes: 1 addition & 1 deletion content/web/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
title : Web
description: Front-end Webapps, smartphone and real world use cases with buttons
date: 2020-12-31T00:00:00+00:00
order: 10
order: 6
---
61 changes: 54 additions & 7 deletions integrations/create_menu.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {dirname, join} from 'path'
import { load_yaml, save_json } from '../src/libs/utils.js';
import { exists, load_yaml, load_yaml_abs,save_json } from '../src/libs/utils.js';
import { section_from_pathname,add_base } from '../src/libs/assets.js';
import {pages_list_to_tree} from './process_menu.js'
import {getDocuments} from 'content-structure'
import {createHash} from 'crypto'
import { config } from '../config.js';
import { readdir, stat } from 'fs/promises';
import path from 'path';

function content_entry_to_level(entry){
const base_level = 1
Expand Down Expand Up @@ -62,26 +64,71 @@ async function get_section_menu(section,raw_menu){
return result_items
}

async function create_raw_menu(content_path){
const items = await readdir(content_path, { withFileTypes: true });
const directories = items.filter(dirent => dirent.isDirectory());
// Map the directories to your desired structure
const structure = directories.map(dir => ({
label: dir.name.charAt(0).toUpperCase() + dir.name.slice(1),
link: `/${dir.name}`,
autogenerate: {
directory: dir.name
}
}));

let homeIndex = -1;
const homeStructure = structure.map((entry, index) => {
if (entry.link === "/home") {
homeIndex = index; // Capture the index of the modified entry
return {
label: entry.label,
link: "/"
};
}
return entry;
});

// If "/home" was modified, move it to the beginning of the array
if (homeIndex !== -1) {
const [homeEntry] = homeStructure.splice(homeIndex, 1); // Remove the entry
homeStructure.unshift(homeEntry); // Unshift to the beginning
}

const icons_file = join(content_path,"icons.yaml")
if(await exists(icons_file)){
const icons_list = await load_yaml_abs(icons_file)
homeStructure.push(...icons_list)
}
return homeStructure;
}

async function create_menu(collect_config){
let raw_menu = await load_yaml(collect_config.raw_menu)
for(const menu_entry of raw_menu){
const menu_file = join(collect_config.contentdir,"menu.yaml")
let raw_menu
if(await exists(menu_file)){
raw_menu = await load_yaml_abs(menu_file)
}else{
raw_menu = await create_raw_menu(join(collect_config.contentdir))
}
const base_menu = JSON.parse(JSON.stringify(raw_menu))
for(let menu_entry of base_menu){
menu_entry.link = add_base(menu_entry.link)
}
let menu = {
raw_menu:raw_menu,
base_menu:base_menu,
sections:{}
}
for(const menu_entry of raw_menu){
for(const menu_entry of base_menu){
const section = section_from_pathname(menu_entry.link);
menu.sections[section] = await get_section_menu(section,raw_menu)
menu.sections[section] = await get_section_menu(section,base_menu)
}

const menu_text = JSON.stringify(menu)
const hash = createHash('md5').update(menu_text).digest('hex').substring(0,8)

menu = {hash:hash,...menu}
await save_json(menu,collect_config.out_menu)
console.log(`create_menu> ${collect_config.raw_menu} -> saved new menu in '${collect_config.out_menu}' `)
console.log(`create_menu> content -> saved new menu in '${collect_config.out_menu}' `)
}

export{
Expand Down
29 changes: 0 additions & 29 deletions menu.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@google/model-viewer": "^3.4.0",
"@svgdotjs/svg.js": "^3.1.2",
"astro": "^4.5.10",
"content-structure": "^1.0.7",
"content-structure": "^1.1.1",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"datatables.net-dt": "^1.13.7",
Expand Down
11 changes: 3 additions & 8 deletions src/layout/AppBar.astro
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
---
import './colors.css';
import Icon from "@/components/icon.astro"
import { load_yaml } from '@/libs/utils';
import { get_active_appbar_menu } from './layout_utils.js';
import { add_base } from '@/libs/assets.js';
import { get_base_menu,get_active_appbar_menu } from './layout_utils.js';
let raw_menu = await load_yaml("menu.yaml")
for(const menu_entry of raw_menu){
menu_entry.link = add_base(menu_entry.link)
}
const menu = get_active_appbar_menu(raw_menu,Astro.url.pathname)
let base_menu = get_base_menu()
const menu = get_active_appbar_menu(base_menu,Astro.url.pathname)
const left_side = menu.filter((item)=>(!Object.hasOwn(item,"align") || !(item.align=="right")))
const right_side = menu.filter((item)=>(Object.hasOwn(item,"align") && (item.align=="right")))
Expand Down
5 changes: 5 additions & 0 deletions src/layout/layout_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,14 @@ function get_menu_hash(){
return generated_menu.hash
}

function get_base_menu(){
return generated_menu.base_menu
}

export{
process_toc_list,
get_generated_section_menu,
get_menu_hash,
get_base_menu,
get_active_appbar_menu
}
7 changes: 7 additions & 0 deletions src/libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ async function save_json(data,file_path){
await writeFile(file_abs,JSON.stringify(data,undefined, 2))
}

async function load_yaml_abs(abs_path){
const fileContent = await readFile(abs_path,'utf-8')
const data = yaml.load(fileContent);
return data;
}

async function load_yaml(rel_path){
const path = join(config.rootdir,rel_path)
const fileContent = await readFile(path,'utf-8')
Expand All @@ -67,6 +73,7 @@ export{
load_json,
load_json_abs,
load_yaml,
load_yaml_abs,
save_json,
save_file,
get_dir_files
Expand Down
4 changes: 2 additions & 2 deletions src/pages/assets/[...path].js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createReadStream } from 'fs';
import {resolve,join} from 'path'
import { config } from "@/config";
import {load_json} from '@/libs/utils.js'
import {load_json_abs} from '@/libs/utils.js'
import {file_mime} from '@/libs/assets.js'
import {remove_base} from '@/libs/assets.js'

Expand Down Expand Up @@ -32,7 +32,7 @@ export async function getStaticPaths(){
return []
}

const asset_list = await load_json(join(config.collect_content.rel_outdir,'asset_list.json'))
const asset_list = await load_json_abs(join(config.collect_content.outdir,'asset_list.json'))
const paths = asset_list.filter((asset)=>(Object.hasOwn(asset,"path"))).map((entry)=>(entry.path))
console.log(`serving API endpoit ${paths.length} assets`)
return paths.map((path)=>({params:{path:path}}))
Expand Down
4 changes: 2 additions & 2 deletions src/pages/codes/[...path].js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createReadStream } from 'fs';
import {resolve,join} from 'path'
import { config } from "@/config";
import {load_json} from '@/libs/utils.js'
import {load_json_abs} from '@/libs/utils.js'
import {file_mime} from '@/libs/assets.js'

export async function GET({params}){
Expand All @@ -21,7 +21,7 @@ export async function GET({params}){

export async function getStaticPaths(){
if(import.meta.env.DEV){
const asset_list = await load_json(join(config.collect_content.rel_outdir,'asset_list.json'))
const asset_list = await load_json_abs(join(config.collect_content.outdir,'asset_list.json'))
const codes_diagrams = ["plantuml", "blockdiag", "mermaid"]
const diagrams = asset_list.filter((asset)=>
((asset.type == "code") && (codes_diagrams.includes(asset.language)))
Expand Down

0 comments on commit aeb05bf

Please sign in to comment.