Skip to content

Commit 38a861a

Browse files
authored
feat: トップページを刷新, 各ページ上部に現在の章のタイトルを表示するように (#56)
1 parent 6797c33 commit 38a861a

4 files changed

Lines changed: 99 additions & 27 deletions

File tree

docs/.vitepress/config.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { head } from './ga-plugin';
1111
// https://vitepress.dev/reference/site-config
1212

1313
export default withMermaid({
14-
title: "pg-basic text",
14+
title: "プログラミング基礎講習会",
1515
description: "プログラミング基礎講習会テキスト",
1616
cleanUrls: true,
1717
markdown: {
@@ -34,11 +34,14 @@ export default withMermaid({
3434
},
3535
nav: [
3636
{ text: 'ホーム', link: '/' },
37-
{ text: 'テキスト', link: '/text/chapter-0/' }
3837
],
3938

4039
sidebar: {
4140
'/cpp/': [
41+
{
42+
text: '2025年度版テキスト',
43+
link: '/text/chapter-0/',
44+
},
4245
{
4346
text: 'はじめに',
4447
link: '/cpp/preface/',
@@ -57,6 +60,10 @@ export default withMermaid({
5760
},
5861
],
5962
'/text/': [
63+
{
64+
text: '2026年度版テキスト [WIP]',
65+
link: '/cpp/preface/',
66+
},
6067
{
6168
text: 'About',
6269
items: [
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<script setup lang="ts">
2+
import { computed } from 'vue'
3+
import { useData, useRoute } from 'vitepress'
4+
import type { DefaultTheme } from 'vitepress'
5+
6+
const { theme } = useData()
7+
const route = useRoute()
8+
9+
function normalize(path: string): string {
10+
return path.replace(/\/$/, '')
11+
}
12+
13+
function findInItems(items: DefaultTheme.SidebarItem[], path: string): boolean {
14+
return items.some(item => {
15+
if (normalize(item.link ?? '') === path) return true
16+
if (item.items) return findInItems(item.items, path)
17+
return false
18+
})
19+
}
20+
21+
const chapterTitle = computed(() => {
22+
const path = normalize(route.path)
23+
const sidebar = theme.value.sidebar as Record<string, DefaultTheme.SidebarItem[]>
24+
25+
const sidebarKey = Object.keys(sidebar).find(key =>
26+
path.startsWith(normalize(key))
27+
)
28+
if (!sidebarKey) return null
29+
30+
for (const section of sidebar[sidebarKey]) {
31+
if (!section.items) continue
32+
if (findInItems(section.items, path)) return section.text
33+
}
34+
return null
35+
})
36+
</script>
37+
38+
<template>
39+
<p v-if="chapterTitle" class="chapter-title">{{ chapterTitle }}</p>
40+
</template>
41+
42+
<style scoped>
43+
.chapter-title {
44+
font-size: 0.85em;
45+
font-weight: 500;
46+
color: var(--vp-c-brand-1);
47+
margin: 0 0 0.25rem;
48+
}
49+
</style>

docs/.vitepress/theme/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
/// <reference types="vite/client" />
2+
import { h } from 'vue'
13
import DefaultTheme from "vitepress/theme";
4+
import ChapterTitle from './ChapterTitle.vue'
25

36
import './custom.css'
47

5-
export default DefaultTheme
8+
export default {
9+
extends: DefaultTheme,
10+
Layout() {
11+
return h(DefaultTheme.Layout, null, {
12+
'doc-before': () => h(ChapterTitle),
13+
})
14+
},
15+
}

docs/index.md

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,42 @@ hero:
88
tagline: "プログラミング基礎講習会テキスト"
99
actions:
1010
- theme: brand
11-
text: テキストを開く
12-
link: /text/chapter-0/
11+
text: テキスト(2026年度版)
12+
link: /cpp/preface/
1313
- theme: alt
1414
text: このテキストについて
1515
link: /about
1616
- theme: alt
1717
text: プライバシーポリシー
1818
link: /privacy-policy
1919

20-
features:
21-
- title: 0. はじめに
22-
details: 講習を受ける上での心構えと環境構築
23-
link: /text/chapter-0/
24-
- title: I. はじめてのプログラミング
25-
details: 「プログラミング」と前提知識を知り、触れる
26-
link: /text/chapter-1/
27-
- title: II. 変数と入出力
28-
details: 入出力と変数・演算で基本的なプログラムの作成
29-
link: /text/chapter-2/
30-
- title: III. 演算・計算
31-
details: 条件分岐や、小数型・文字列型
32-
link: /text/chapter-3/
33-
- title: IV. 繰り返し処理
34-
details: 繰り返し処理と、文字列の操作
35-
link: /text/chapter-4/
36-
- title: V. Function
37-
details: 関数・再帰を用いた実装
38-
link: /text/chapter-5/
39-
- title: VI. Struct
40-
details: 便利にプログラミングをするための概念
41-
link: /text/chapter-6/
20+
4221
---
4322

23+
現在2026年度版のテキストを作成中です。構成の変更や内容の追加などを行っています。執筆が完了した章から順次公開していきます。
24+
25+
- [はじめに](/cpp/preface/)
26+
- [この講習会について](/cpp/preface/1)
27+
- [このテキストについて](/cpp/preface/2)
28+
- [1. 環境構築](/cpp/chapter-1/)
29+
- [1-A. Macの環境構築](/cpp/chapter-1/1-A)
30+
- [1-B. Windowsの環境構築](/cpp/chapter-1/1-B)
31+
- [2. はじめてのプログラミング](/cpp/chapter-2/)
32+
- [2.1 プログラミングの基礎知識](/cpp/chapter-2/1)
33+
- [2.2 作業環境の構築](/cpp/chapter-2/2)
34+
- [2.3 はじめてのプログラミング](/cpp/chapter-2/3)
35+
- [練習問題](/cpp/chapter-2/problems/)
36+
37+
:::details 2025年度版テキスト
38+
39+
こちらは2025年度以前に使用していたテキストです。
40+
41+
- [0. はじめに](/text/chapter-0/)
42+
- [I. はじめてのプログラミング](/text/chapter-1/)
43+
- [II. 変数と入出力](/text/chapter-2/)
44+
- [III. 演算・計算](/text/chapter-3/)
45+
- [IV. 繰り返し処理](/text/chapter-4/)
46+
- [V. Function](/text/chapter-5/)
47+
- [VI. Struct](/text/chapter-6/)
48+
49+
:::

0 commit comments

Comments
 (0)