Merge branch 'main' of https://framagit.org/isUnknown/pdc-b2b-project-management-platform
* 'main' of https://framagit.org/isUnknown/pdc-b2b-project-management-platform: add dependencies to documentation document new route
This commit is contained in:
commit
57184128c7
4 changed files with 88 additions and 57 deletions
70
README.md
70
README.md
|
|
@ -1,5 +1,26 @@
|
||||||
The project is based on [Kirby CMS](https://getkirby.com), [Vite](https://vitejs.dev/) + [Vue](https://fr.vuejs.org/) and [Pinia](https://pinia.vuejs.org/) as a state manager.
|
The project is based on
|
||||||
Vue is used following the composition API approach.
|
|
||||||
|
- [Kirby CMS](https://getkirby.com) as the content management system
|
||||||
|
- [Vite](https://vitejs.dev/) as the build tool
|
||||||
|
- [Vue](https://fr.vuejs.org/) as the JavaScript framework
|
||||||
|
- [Vue Router](https://router.vuejs.org) for handling routing
|
||||||
|
[Pinia](https://pinia.vuejs.org/) as a state management library.
|
||||||
|
|
||||||
|
Vue is used with the composition API approach.
|
||||||
|
|
||||||
|
The project also includes some helper libraries that are available throughout the /src directory. These libraries include:
|
||||||
|
|
||||||
|
- [dayjs](https://day.js.org/): a lightweight JavaScript date library for parsing, manipulating, and formatting dates. To use dayjs in your code, you can import it like this:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
```
|
||||||
|
|
||||||
|
- [slugify](https://www.npmjs.com/package/slugify): a library for converting strings into URL-friendly slugs. To use slugify in your code, you can import it like this:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import slugify from "slugify";
|
||||||
|
```
|
||||||
|
|
||||||
# Development
|
# Development
|
||||||
|
|
||||||
|
|
@ -42,11 +63,12 @@ VITE_PASSWORD=your-private-password
|
||||||
|
|
||||||
### Creating a page
|
### Creating a page
|
||||||
|
|
||||||
Templates are managed through Vue (`/src/views`). Thus, the process for creating new pages differs from the Kirby usual one. In addition to the **blueprint** (`/public/site/blueprints/pages/example.yml`) and **template** (`/public/site/templates/example.php`) files, it needs at least a **content representation** (`/public/site/templates/example.json.php`) and a **view component** (`/src/views/Example.vue`) ones.
|
Templates are managed through Vue (`/src/views`). Thus, the process for creating new pages differs from the Kirby usual one. In addition to the **blueprint** (`/public/site/blueprints/pages/example.yml`) and **template** (`/public/site/templates/example.php`) files and the corresponding content directory (`/public/content/<page-uri>/<template>.txt`), it needs at least a **content representation** (`/public/site/templates/example.json.php`) and a **view component** (`/src/views/Example.vue`) ones.
|
||||||
|
|
||||||
1. **Create the blueprint** as usual.
|
1. **Create the blueprint** as usual.
|
||||||
2. **Create the corresponding template**. Distincts templates are needed, but all of them should contain this same single line of code (that you can also find in `/public/site/templates/example.php`) : `<?php snippet('generic-template') ?>`.
|
2. **Create the corresponding template**. Distincts templates are needed, but all of them should contain this same single line of code (that you can also find in `/public/site/templates/example.php`) : `<?php snippet('generic-template') ?>`.
|
||||||
3. **Create the corresponding [content representation](https://getkirby.com/docs/guide/templates/content-representations)** following this code (also in `/public/site/templates/example.json.php`) :
|
3. **Create the corresponding content directory**. Put the `<template-name>.txt` within.
|
||||||
|
4. **Create the corresponding [content representation](https://getkirby.com/docs/guide/templates/content-representations)** following this code (also in `/public/site/templates/example.json.php`) :
|
||||||
|
|
||||||
```php
|
```php
|
||||||
<?php
|
<?php
|
||||||
|
|
@ -63,34 +85,44 @@ echo json_encode($data);
|
||||||
|
|
||||||
`$genericData` are defined in the `/public/site/controllers/site.php` controllers. By default, it contains a simple representation of the page object.
|
`$genericData` are defined in the `/public/site/controllers/site.php` controllers. By default, it contains a simple representation of the page object.
|
||||||
|
|
||||||
4. **Create the corresponding views** in `/src/views/`. It's just a simple vue component that heritates data through the props (also in `/src/views/Example.vue`) :
|
4. **Create the corresponding views** in `/src/views/`. It's just a simple vue component that heritates the page data through the page object (also in `/src/views/Example.vue`) :
|
||||||
|
|
||||||
```vue
|
```vue
|
||||||
<template>
|
<template>
|
||||||
<h1>{{ data.content.title }}</h1>
|
<h1>{{ page.content.title }}</h1>
|
||||||
<!-- ... -->
|
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
|
||||||
const { data } = defineProps({
|
|
||||||
data: Object,
|
|
||||||
});
|
|
||||||
|
|
||||||
// ....
|
<script setup>
|
||||||
|
import { usePageStore } from "../stores/page";
|
||||||
|
import { storeToRefs } from "pinia";
|
||||||
|
|
||||||
|
const { page } = storeToRefs(usePageStore());
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
5. **Import the view** in the `/src/App.vue` root component :
|
5. **Create the route** in the `/src/router/routes.js`. A route is a combination of a path and a corresponding component. The path can include variable parameters, which can be captured and passed to the component. To create a route, you need to import the component and add an object to the routes array. See the [Vue Router documentation](https://router.vuejs.org/guide/) for more information.
|
||||||
|
|
||||||
```vue
|
```vue
|
||||||
<script setup>
|
<script setup>
|
||||||
...
|
import ExampleView from "../views/ExampleView.vue";
|
||||||
import example from "./views/Example.vue";
|
|
||||||
|
|
||||||
const components = {
|
const routes = [
|
||||||
example
|
// Existing routes go here...
|
||||||
};
|
{
|
||||||
|
// This is a static route without any variable parameters
|
||||||
|
path: "/page-uri",
|
||||||
|
component: ExampleView,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// This is a dynamic route with a variable parameter :title
|
||||||
|
path: "/page-uri/:title",
|
||||||
|
component: ExampleView,
|
||||||
|
// OPTIONAL. The props: true option allows the route parameters to be passed as props to the component.
|
||||||
|
props: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
...
|
export default routes;
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,9 @@
|
||||||
import { createWebHistory, createRouter } from "vue-router";
|
import { createWebHistory, createRouter } from "vue-router";
|
||||||
import Home from "../views/Home.vue";
|
import routes from "./routes";
|
||||||
import Notifications from "../views/Notifications.vue";
|
|
||||||
import Reunions from "../views/Reunions.vue";
|
|
||||||
import Inspirations from "../views/Inspirations.vue";
|
|
||||||
import Project from "../views/Project.vue";
|
|
||||||
import { useApiStore } from "../stores/api";
|
import { useApiStore } from "../stores/api";
|
||||||
import { usePageStore } from "../stores/page";
|
import { usePageStore } from "../stores/page";
|
||||||
import { getActivePinia } from "pinia";
|
import { getActivePinia } from "pinia";
|
||||||
|
|
||||||
const routes = [
|
|
||||||
{
|
|
||||||
path: "/",
|
|
||||||
component: Home,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/notifications",
|
|
||||||
component: Notifications,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/reunions",
|
|
||||||
component: Reunions,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/inspirations",
|
|
||||||
component: Inspirations,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/projects/:id",
|
|
||||||
component: Project,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(),
|
history: createWebHistory(),
|
||||||
routes,
|
routes,
|
||||||
|
|
|
||||||
30
src/router/routes.js
Normal file
30
src/router/routes.js
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
import Home from "../views/Home.vue";
|
||||||
|
import Notifications from "../views/Notifications.vue";
|
||||||
|
import Reunions from "../views/Reunions.vue";
|
||||||
|
import Inspirations from "../views/Inspirations.vue";
|
||||||
|
import Project from "../views/Project.vue";
|
||||||
|
|
||||||
|
const routes = [
|
||||||
|
{
|
||||||
|
path: "/",
|
||||||
|
component: Home,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/notifications",
|
||||||
|
component: Notifications,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/reunions",
|
||||||
|
component: Reunions,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/inspirations",
|
||||||
|
component: Inspirations,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/projects/:id",
|
||||||
|
component: Project,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export default routes;
|
||||||
|
|
@ -1,16 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<h1>{{ data.content.title }}</h1>
|
<h1>{{ page.content.title }}</h1>
|
||||||
<!-- ... -->
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
const { data } = defineProps({
|
import { usePageStore } from "../stores/page";
|
||||||
data: Object,
|
import { storeToRefs } from "pinia";
|
||||||
});
|
|
||||||
|
|
||||||
// ....
|
const { page } = storeToRefs(usePageStore());
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue