Skip to content

Commit ee10b73

Browse files
committed
support top readme as home
1 parent eb6c781 commit ee10b73

File tree

6 files changed

+33
-29
lines changed

6 files changed

+33
-29
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ for development of content-structure it is possible to replace the registry vers
3939

4040
# Ideas
4141
- support different icon types (.svg, .ico, .png) and allow it in content root
42-
- top readme.md in content used as home
4342
- public folder inside content and ignored by content structure
4443
- .structureignore to allow e.g. .git/workflow/deploy.yaml
45-
- test mixture of readme page with filenames and folders
4644
- fix consistency of top menu folder name different than slug
4745
- Code
4846
- keep separate plantuml and kroki (due to perf reason)
@@ -53,6 +51,7 @@ for development of content-structure it is possible to replace the registry vers
5351
- PanZoom
5452
- URL params, zoom on text, multiple hits counter
5553
- update pan zoom status in url on mouse up
54+
- watch and regenrate .structure on save for modified files only
5655
- check potential replacement of scrollspy with intersection Observer API
5756
- enhance intersection to cover a path of all visible sections from the page in the toc : start heading, stop heading
5857

content/examples/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
title: Examples
23
order: 2
34
---
45
All examples are listed in this section

content/home/readme.md renamed to content/readme.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ link to [svg image](#svg-image)
1111
Images are encapsulated inside a component that can open them in a Modal full view for Pan and zoom function
1212

1313
```markdown
14-
![astro markdown render](./astro-markdown-render-small.png)
14+
![astro markdown render](./home/astro-markdown-render-small.png)
1515
```
1616

1717
will generate this image
1818

19-
![astro markdown render](./astro-markdown-render-small.png)
19+
![astro markdown render](./home/astro-markdown-render-small.png)
2020

2121
## Advanced Image Directive
2222
In order to give more options, using the image directive allows to pass more arguments from markdown
2323

2424
```markdown
25-
:image[]{src=./astro-markdown-render-small.png alt="Astro Markdown Render" height=200 center}
25+
:image[]{src=./home/astro-markdown-render-small.png alt="Astro Markdown Render" height=200 center}
2626
```
2727

2828
will generate this image height adjusted size. Aspect ratio is conserved even when giving either of width or height. It is also possible to center the image.
2929

30-
:image[]{src=./astro-markdown-render-small.png alt="Astro Markdown Render" height=200 center}
30+
:image[]{src=./home/astro-markdown-render-small.png alt="Astro Markdown Render" height=200 center}
3131

3232
## SVG Image
3333

34-
![Tree](./tree.svg)
34+
![Tree](./home/tree.svg)
3535

3636

3737
## Gallery
@@ -52,12 +52,12 @@ This is a Gallery Astro component, a yaml Code block with metadata 'gallery' is
5252
will generate this gallery
5353

5454
```yaml pz_gallery
55-
- tree.svg
56-
- images/gallery-tiger.svg
57-
- images/gallery-long_diag.svg
58-
- images/gallery-Linux_kernel_map.svg
59-
- images/gallery-tiger.svg
60-
- images/github-dark.png
55+
- home/tree.svg
56+
- home/images/gallery-tiger.svg
57+
- home/images/gallery-long_diag.svg
58+
- home/images/gallery-Linux_kernel_map.svg
59+
- home/images/gallery-tiger.svg
60+
- home/images/github-dark.png
6161
```
6262
6363
## Cards
@@ -95,18 +95,18 @@ models from https://modelviewer.dev/editor/
9595
just by inserting a link to a .glb file
9696

9797
```markdown
98-
[Astronaut](./Astronaut.glb)
98+
[Astronaut](./home/Astronaut.glb)
9999
```
100100
will generate this 3D model
101101

102-
[Astronaut](./Astronaut.glb)
102+
[Astronaut](./home/Astronaut.glb)
103103

104104

105105
## From code
106106
This piece of code using as code language `yaml` and code meta-data : `glb` as follows
107107

108108

109-
![Code](./code.png)
109+
![Code](./home/code.png)
110110

111111
will generate this 3D model with the provided files.
112112
* poster : allows fast page load, by loading the image only first.
@@ -115,7 +115,7 @@ will generate this 3D model with the provided files.
115115
```yaml glb
116116
src: Lantern.glb
117117
title: Lantern
118-
poster: Lantern.webp
118+
poster: home/Lantern.webp
119119
environment-image: spruit_sunrise_1k_HDR.hdr
120120
```
121121

@@ -164,11 +164,11 @@ A table with a high number of lines gets a [data-table](https://datatables.net/)
164164
It is also possible to create tables in xlsx format. This link of `.xlsx` extension
165165

166166
```markdown
167-
[Table1](./Table1.xlsx)
167+
[Table1](./home/Table1.xlsx)
168168
```
169169
will generate this data table
170170

171-
[Table1](./Table1.xlsx)
171+
[Table1](./home/Table1.xlsx)
172172

173173
# Notes
174174
A note can be created like this and can have markdown inside

integrations/create_menu.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ async function get_section_menu(section,raw_menu){
4747
}
4848

4949
async function create_raw_menu(content_path,document_list){
50-
const top_items = document_list.filter((item)=> item.level === 2).sort((a,b)=> a.order-b.order)
50+
let top_items = document_list.filter((item)=> item.level === 2).sort((a,b)=> a.order-b.order)
51+
const home_item = document_list.find((item)=> item.level === 1)
52+
if(home_item){
53+
top_items = [home_item,...top_items]
54+
}
5155
const sorted_items = top_items.map(entry => ({
5256
label: entry.title,
5357
link: `/${entry.url}`,
@@ -56,13 +60,12 @@ async function create_raw_menu(content_path,document_list){
5660
}
5761
}));
5862

59-
const home_items = sorted_items.map(item => item.link === '/home' ? { ...item, link: '/' } : item);
6063
const icons_file = join(content_path,"icons.yaml")
6164
if(await exists(icons_file)){
6265
const icons_list = await load_yaml_abs(icons_file)
63-
home_items.push(...icons_list)
66+
sorted_items.push(...icons_list)
6467
}
65-
return home_items;
68+
return sorted_items;
6669
}
6770

6871
async function create_menu(collect_config){
@@ -84,7 +87,9 @@ async function create_menu(collect_config){
8487
}
8588
for(const menu_entry of base_menu){
8689
const section = section_from_pathname(menu_entry.link);
87-
menu.sections[section] = await get_section_menu(section,base_menu)
90+
if(section != "home"){
91+
menu.sections[section] = await get_section_menu(section,base_menu)
92+
}
8893
}
8994

9095
const menu_text = JSON.stringify(menu)

src/pages/index.astro

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import AstroMarkdown from '@/components/markdown/AstroMarkdown.astro'
44
import {getEntry} from 'content-structure'
55
66
console.log(`index> home page`)
7-
const entry = await getEntry({path:"home/readme.md"})
8-
const not_empty = !(Object.keys(entry.tree).length == 0)
9-
7+
let entry = await getEntry({url:""})
8+
let empty = (Object.keys(entry.tree).length == 0)
109
const headings = (Object.hasOwn(entry.data,"toc")&&entry.data.toc == false)?[]:entry.data.headings
1110
1211
---
1312
<Layout title={entry.data.title} headings={headings} >
14-
{not_empty&&
13+
{!empty&&
1514
<AstroMarkdown node={entry.tree} data={entry.data} />
1615
}
1716
</Layout>

0 commit comments

Comments
 (0)