Compare commits
No commits in common. 'main' and 'next-astro' have entirely different histories.
main
...
next-astro
@ -1,50 +0,0 @@
|
||||
# This file defines a Drone pipeline that builds a static website with "npm run build". This
|
||||
# pipeline must be marked as "Trusted" in the Drone project settings.
|
||||
#
|
||||
# We mount the target directory of the project at "/var/www/{project}" to the container
|
||||
# "dist/" directory and the run the build. A caveat is that the container builds files
|
||||
# with "root" permissions, so we need to fix those after each build with a second pipeline.
|
||||
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: deploy
|
||||
image: node:latest
|
||||
volumes:
|
||||
- name: host-website-dist
|
||||
path: /mnt/website
|
||||
commands:
|
||||
- npm install
|
||||
- npm run build
|
||||
- cp -rT ./dist /mnt/website
|
||||
|
||||
volumes:
|
||||
- name: host-website-dist
|
||||
host: # this volume is mounted on the host machine
|
||||
path: /var/www/website
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- main
|
||||
event:
|
||||
- push
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: exec # this job is executed on the host machine
|
||||
name: caddy-permissions
|
||||
|
||||
depends_on:
|
||||
- default
|
||||
|
||||
steps:
|
||||
- name: chown
|
||||
commands:
|
||||
- chown -R caddy:caddy /var/www/website
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- main
|
||||
event:
|
||||
- push
|
@ -1,23 +1,8 @@
|
||||
# build output
|
||||
dist/
|
||||
# generated types
|
||||
.astro/
|
||||
|
||||
# dependencies
|
||||
node_modules/
|
||||
|
||||
# logs
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
|
||||
# local data
|
||||
*.local*
|
||||
|
||||
# environment variables
|
||||
.env
|
||||
.env.production
|
||||
*.local*
|
||||
bin/
|
||||
|
||||
# macOS-specific files
|
||||
.DS_Store
|
||||
.out/
|
||||
out/
|
||||
dist/
|
||||
node_modules/
|
||||
|
@ -1,27 +0,0 @@
|
||||
/** @type {import("prettier").Config} */
|
||||
export default {
|
||||
printWidth: 120,
|
||||
singleQuote: true,
|
||||
quoteProps: 'consistent',
|
||||
tabWidth: 4,
|
||||
useTabs: false,
|
||||
semi: false,
|
||||
arrowParens: 'avoid',
|
||||
|
||||
plugins: ['prettier-plugin-astro'],
|
||||
overrides: [
|
||||
{
|
||||
files: '*.astro',
|
||||
options: {
|
||||
parser: 'astro',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: '*.{yml,yaml,json}',
|
||||
excludeFiles: 'package-lock.json',
|
||||
options: {
|
||||
tabWidth: 2,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
{
|
||||
"npm.packageManager": "bun",
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"[astro]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"[yaml]": {
|
||||
"editor.tabSize": 2,
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
|
||||
.PHONY: all
|
||||
all: frontend backend
|
||||
|
||||
.PHONY: frontend
|
||||
frontend:
|
||||
$(NPM) run build
|
||||
|
||||
.PHONY: backend
|
||||
backend:
|
||||
go build -v -o ./out/server ./cmd/server
|
@ -0,0 +1,15 @@
|
||||
import { defineConfig } from 'astro/config'
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({
|
||||
publicDir: './client/public',
|
||||
srcDir: './client',
|
||||
outDir: './out/client',
|
||||
vite: {
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': 'http://127.0.0.1:4000',
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
@ -1,28 +0,0 @@
|
||||
import { defineConfig } from 'astro/config'
|
||||
import preact from '@astrojs/preact'
|
||||
|
||||
import mdx from '@astrojs/mdx'
|
||||
|
||||
import yaml from '@rollup/plugin-yaml'
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({
|
||||
vite: {
|
||||
plugins: [yaml()],
|
||||
},
|
||||
server: {
|
||||
port: 3000,
|
||||
},
|
||||
markdown: {
|
||||
shikiConfig: {
|
||||
theme: 'github-light',
|
||||
},
|
||||
},
|
||||
integrations: [
|
||||
preact({
|
||||
compat: true,
|
||||
}),
|
||||
mdx(),
|
||||
],
|
||||
output: 'static',
|
||||
})
|
@ -0,0 +1 @@
|
||||
/// <reference types="astro/client" />
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
import PageLayout from './PageLayout.astro'
|
||||
|
||||
const { frontmatter } = Astro.props
|
||||
---
|
||||
|
||||
<PageLayout {...frontmatter} />
|
@ -0,0 +1,28 @@
|
||||
---
|
||||
import '@fontsource/open-sans/latin.css'
|
||||
import '@fontsource/source-sans-pro/latin.css'
|
||||
import '@fontsource/source-code-pro/latin.css'
|
||||
|
||||
import '../styles/main.scss'
|
||||
|
||||
const { title, description, thumbnail, pageName } = Astro.props
|
||||
---
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
<meta property="og:title" content={title ?? 'PHC'} />
|
||||
<meta property="og:description" content={description ?? 'Sito web del PHC'} />
|
||||
{thumbnail && <meta property="og:image" content={thumbnail} />}
|
||||
|
||||
<link rel="icon" type="image/png" sizes="512x512" href="/assets/icon.png" />
|
||||
|
||||
<title>{title}</title>
|
||||
</head>
|
||||
<body class:list={['page-' + (pageName ?? 'unknown')]}>
|
||||
<slot />
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,22 @@
|
||||
---
|
||||
import BaseLayout from './BaseLayout.astro'
|
||||
---
|
||||
|
||||
<BaseLayout {...Astro.props}>
|
||||
<header>
|
||||
<div class="logo">
|
||||
<img src="/images/logo-circuit-board.svg" alt="phc logo" />
|
||||
</div>
|
||||
<div class="links">
|
||||
<a role="button" href="#">Utenti</a>
|
||||
<a role="button" href="#">Notizie</a>
|
||||
<a role="button" href="#">Progetti</a>
|
||||
<a role="button" href="#">About</a>
|
||||
<a class="primary" role="button" href="#">Accedi</a>
|
||||
</div>
|
||||
</header>
|
||||
<main>
|
||||
<slot />
|
||||
</main>
|
||||
<footer>© PHC 2023</footer>
|
||||
</BaseLayout>
|
@ -0,0 +1,199 @@
|
||||
---
|
||||
import PageLayout from '../layouts/PageLayout.astro'
|
||||
---
|
||||
|
||||
<PageLayout pageName="homepage">
|
||||
<section class="principal">
|
||||
<div class="circuit-layer">
|
||||
<canvas id="circuits-art"></canvas>
|
||||
<script src="../scripts/circuits-art.ts"></script>
|
||||
</div>
|
||||
<div class="logo">
|
||||
<img src="/images/logo-circuit-board.svg" alt="phc logo" />
|
||||
</div>
|
||||
<div class="whats-phc">
|
||||
<div class="title">Cos'è il PHC?</div>
|
||||
<div class="content">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Totam vero deserunt tempore reprehenderit atque, voluptate
|
||||
dolorum excepturi libero pariatur sequi?
|
||||
</p>
|
||||
<p>
|
||||
Laboriosam soluta ab a illum mollitia quaerat quia, veniam consequatur expedita dolore autem reiciendis quae rem
|
||||
excepturi optio? Maiores, hic?
|
||||
</p>
|
||||
<p>
|
||||
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Exercitationem error atque amet. Tempora earum nemo eveniet
|
||||
aspernatur quam quas, doloribus expedita quisquam dignissimos cupiditate inventore a modi optio harum veritatis,
|
||||
adipisci ab ullam distinctio odio quod delectus ipsum, rerum animi.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="news">
|
||||
<div class="zig-zag">
|
||||
<svg width="100%" height="2rem" viewBox="0 0 1 1" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMid meet">
|
||||
<defs>
|
||||
<pattern id="zig-zag-1" x="0" y="0" width="2" height="1" patternUnits="userSpaceOnUse">
|
||||
<path fill="#C2A8EB" d="M 0,1 L 1,0 L 2,1 L 0,1"></path>
|
||||
</pattern>
|
||||
</defs>
|
||||
<rect fill="url(#zig-zag-1)" x="0" y="0" width="1000" height="1"></rect>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="title">Ultime Notizie</div>
|
||||
|
||||
<div class="news-list">
|
||||
<div class="news">
|
||||
<div class="title">Lorem ipsum dolor sit.</div>
|
||||
<div class="abstract">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Debitis reprehenderit porro omnis enim deleniti esse quos,
|
||||
architecto adipisci veritatis, iusto perferendis aperiam recusandae exercitationem doloribus, illum commodi
|
||||
voluptatem pariatur eius!
|
||||
</p>
|
||||
<p>
|
||||
Impedit ut quod aspernatur vitae vero incidunt cupiditate perferendis explicabo sunt possimus rerum expedita dicta
|
||||
nesciunt enim mollitia iure ullam aut, pariatur, at cumque. Nemo obcaecati eaque recusandae fugit sed!
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="news">
|
||||
<div class="title">Tempore provident impedit libero?</div>
|
||||
<div class="abstract">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Debitis reprehenderit porro omnis enim deleniti esse quos,
|
||||
architecto adipisci veritatis, iusto perferendis aperiam recusandae exercitationem doloribus, illum commodi
|
||||
voluptatem pariatur eius!
|
||||
</p>
|
||||
<p>
|
||||
Impedit ut quod aspernatur vitae vero incidunt cupiditate perferendis explicabo sunt possimus rerum expedita dicta
|
||||
nesciunt enim mollitia iure ullam aut, pariatur, at cumque. Nemo obcaecati eaque recusandae fugit sed!
|
||||
</p>
|
||||
<p>
|
||||
Impedit ut quod aspernatur vitae vero incidunt cupiditate perferendis explicabo sunt possimus rerum expedita dicta
|
||||
nesciunt enim mollitia iure ullam aut, pariatur, at cumque. Nemo obcaecati eaque recusandae fugit sed!
|
||||
</p>
|
||||
<p>
|
||||
Impedit ut quod aspernatur vitae vero incidunt cupiditate perferendis explicabo sunt possimus rerum expedita dicta
|
||||
nesciunt enim mollitia iure ullam aut, pariatur, at cumque. Nemo obcaecati eaque recusandae fugit sed!
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="news">
|
||||
<div class="title">Alias molestias consectetur quam</div>
|
||||
<div class="abstract">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Debitis reprehenderit porro omnis enim deleniti esse quos,
|
||||
architecto adipisci veritatis, iusto perferendis aperiam recusandae exercitationem doloribus, illum commodi
|
||||
voluptatem pariatur eius!
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="news">
|
||||
<div class="title">Inventore dignissimos sapiente nulla</div>
|
||||
<div class="abstract">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Debitis reprehenderit porro omnis enim deleniti esse quos,
|
||||
architecto adipisci veritatis, iusto perferendis aperiam recusandae exercitationem doloribus, illum commodi
|
||||
voluptatem pariatur eius!
|
||||
</p>
|
||||
<p>
|
||||
Impedit ut quod aspernatur vitae vero incidunt cupiditate perferendis explicabo sunt possimus rerum expedita dicta
|
||||
nesciunt enim mollitia iure ullam aut, pariatur, at cumque. Nemo obcaecati eaque recusandae fugit sed!
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a class="primary" href="#" role="button">Vai all'Archivio</a>
|
||||
</section>
|
||||
<section class="projects">
|
||||
<div class="zig-zag">
|
||||
<svg width="100%" height="2rem" viewBox="0 0 1 1" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMid meet">
|
||||
<defs>
|
||||
<pattern id="zig-zag-2" x="0" y="0" width="2" height="1" patternUnits="userSpaceOnUse">
|
||||
<path fill="#f5f2cc" d="M 0,1 L 1,0 L 2,1 L 0,1"></path>
|
||||
</pattern>
|
||||
</defs>
|
||||
<rect fill="url(#zig-zag-2)" x="0" y="0" width="1000" height="1"></rect>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="title">Progetti</div>
|
||||
|
||||
<div class="project-list">
|
||||
<a href="#">
|
||||
<div class="project">
|
||||
<div class="image">
|
||||
<div class="box"></div>
|
||||
</div>
|
||||
<div class="title">Gitea</div>
|
||||
<div class="description">
|
||||
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Voluptatibus quam iure dolor. Excepturi facere, ipsa
|
||||
accusantium labore explicabo quaerat incidunt.
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
<a href="#">
|
||||
<div class="project">
|
||||
<div class="image">
|
||||
<div class="box"></div>
|
||||
</div>
|
||||
<div class="title">Zulip</div>
|
||||
<div class="description">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Repellendus, veritatis.</div>
|
||||
</div>
|
||||
</a>
|
||||
<a href="#">
|
||||
<div class="project">
|
||||
<div class="image">
|
||||
<div class="box"></div>
|
||||
</div>
|
||||
<div class="title">Orario</div>
|
||||
<div class="description">
|
||||
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Voluptatibus quam iure dolor. Excepturi facere, ipsa
|
||||
accusantium labore explicabo quaerat incidunt.
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
<a href="#">
|
||||
<div class="project">
|
||||
<div class="image">
|
||||
<div class="box"></div>
|
||||
</div>
|
||||
<div class="title">Problemi</div>
|
||||
<div class="description">
|
||||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Non, hic libero beatae voluptatem incidunt.
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
<a href="#">
|
||||
<div class="project">
|
||||
<div class="image">
|
||||
<div class="box"></div>
|
||||
</div>
|
||||
<div class="title">Cluster "Steffè"</div>
|
||||
<div class="description">
|
||||
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Voluptatibus quam iure dolor. Excepturi facere, ipsa
|
||||
accusantium labore explicabo quaerat incidunt.
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</section>
|
||||
<section class="wanna-be-macchinista">
|
||||
<div class="zig-zag">
|
||||
<svg width="100%" height="2rem" viewBox="0 0 1 1" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMid meet">
|
||||
<defs>
|
||||
<pattern id="zig-zag-3" x="0" y="0" width="2" height="1" patternUnits="userSpaceOnUse">
|
||||
<path fill="#888" d="M 0,1 L 1,0 L 2,1 L 0,1"></path>
|
||||
</pattern>
|
||||
</defs>
|
||||
<rect fill="url(#zig-zag-3)" x="0" y="0" width="1000" height="1"></rect>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="title">Vuoi diventare macchinista?</div>
|
||||
</section>
|
||||
</PageLayout>
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 765 B After Width: | Height: | Size: 765 B |
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 1.9 MiB After Width: | Height: | Size: 1.9 MiB |
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 63 KiB |
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
Before Width: | Height: | Size: 4.6 MiB After Width: | Height: | Size: 4.6 MiB |
Before Width: | Height: | Size: 344 B After Width: | Height: | Size: 344 B |
@ -0,0 +1,474 @@
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
font: inherit;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
min-height: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
|
||||
font-family: 'Open Sans', sans-serif;
|
||||
font-size: 18px;
|
||||
color: #222;
|
||||
}
|
||||
|
||||
html {
|
||||
scroll-snap-type: y proximity;
|
||||
scroll-padding-top: 4rem;
|
||||
}
|
||||
|
||||
img {
|
||||
display: block;
|
||||
}
|
||||
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
//
|
||||
// Typography
|
||||
//
|
||||
|
||||
.text {
|
||||
display: block;
|
||||
|
||||
line-height: 1.5;
|
||||
|
||||
p + p {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Controls
|
||||
//
|
||||
|
||||
button,
|
||||
.button,
|
||||
[role='button'] {
|
||||
appearance: none;
|
||||
|
||||
background: #fff;
|
||||
|
||||
border: 3px solid #222;
|
||||
border-radius: 6px;
|
||||
box-shadow: 4px 4px 0 0 #222;
|
||||
|
||||
transition: all 64ms linear;
|
||||
|
||||
&:hover {
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: translate(2px, 2px);
|
||||
box-shadow: 2px 2px 0 0 #222;
|
||||
}
|
||||
|
||||
padding: 0.25rem 1.5rem;
|
||||
|
||||
text-decoration: none;
|
||||
color: #222;
|
||||
|
||||
font-family: 'Source Sans Pro', sans-serif;
|
||||
font-weight: 600;
|
||||
|
||||
&.primary {
|
||||
background: #1e6733;
|
||||
color: #f4fef7;
|
||||
|
||||
&:hover {
|
||||
background: #2b8b47;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Pages
|
||||
//
|
||||
|
||||
header {
|
||||
z-index: 10;
|
||||
|
||||
height: 6rem;
|
||||
border-bottom: 4px solid #222;
|
||||
background: #fff;
|
||||
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.logo {
|
||||
padding-left: 0.5rem;
|
||||
|
||||
img {
|
||||
height: 4rem;
|
||||
}
|
||||
}
|
||||
|
||||
.links {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1.5rem;
|
||||
|
||||
padding: 0 1.5rem;
|
||||
|
||||
a {
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
footer {
|
||||
min-height: 6rem;
|
||||
border-top: 4px solid #222;
|
||||
background: #444;
|
||||
color: #fdfdfd;
|
||||
|
||||
display: grid;
|
||||
place-content: center;
|
||||
|
||||
font-family: 'Source Sans Pro', sans-serif;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.page-homepage {
|
||||
header .logo {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
section {
|
||||
position: relative;
|
||||
|
||||
min-height: calc(100vh - 6rem);
|
||||
|
||||
&:last-of-type {
|
||||
min-height: calc(100vh - 10rem);
|
||||
}
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
|
||||
gap: 2rem;
|
||||
|
||||
scroll-snap-align: start;
|
||||
|
||||
& > .title {
|
||||
font-weight: 700;
|
||||
font-size: 60px;
|
||||
|
||||
font-family: 'Source Sans Pro', sans-serif;
|
||||
|
||||
padding-top: 4rem;
|
||||
}
|
||||
}
|
||||
|
||||
.zig-zag {
|
||||
z-index: 5;
|
||||
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
|
||||
display: flex;
|
||||
|
||||
&:first-child {
|
||||
bottom: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
section.principal {
|
||||
z-index: -2;
|
||||
|
||||
min-height: calc(100vh - 2rem);
|
||||
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6rem;
|
||||
|
||||
padding: 6rem 0;
|
||||
|
||||
background: #ecffe3;
|
||||
// circuit color
|
||||
// background: #a6ce94;
|
||||
|
||||
flex-wrap: wrap;
|
||||
|
||||
position: relative;
|
||||
|
||||
.circuit-layer {
|
||||
z-index: -1;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
padding-top: 6rem;
|
||||
|
||||
canvas {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.logo {
|
||||
max-width: 640px;
|
||||
position: relative;
|
||||
|
||||
user-select: none;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
filter: drop-shadow(6px 6px 0 #222) drop-shadow(4px 0 0 #222) drop-shadow(0 4px 0 #222) drop-shadow(-4px 0 0 #222)
|
||||
drop-shadow(0 -4px 0 #222);
|
||||
}
|
||||
}
|
||||
|
||||
.whats-phc {
|
||||
background: #e4c5ff;
|
||||
|
||||
border: 4px solid #222;
|
||||
border-radius: 8px;
|
||||
box-shadow: 6px 6px 0 0 #222;
|
||||
|
||||
padding: 2rem;
|
||||
|
||||
max-width: 37rem;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
|
||||
gap: 1rem;
|
||||
|
||||
.title {
|
||||
font-family: 'Source Sans Pro', sans-serif;
|
||||
font-weight: 700;
|
||||
font-size: 40px;
|
||||
}
|
||||
|
||||
.content {
|
||||
@extend .text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
section.news {
|
||||
background: #c2a8eb;
|
||||
|
||||
gap: 3rem;
|
||||
|
||||
padding-bottom: 6rem;
|
||||
|
||||
.news-list {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 3rem;
|
||||
|
||||
padding: 0 3rem;
|
||||
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.news {
|
||||
background: #fffbeb;
|
||||
|
||||
border: 3px solid #222;
|
||||
border-radius: 9px;
|
||||
box-shadow: 9px 9px 0 0 #222;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
width: 22rem;
|
||||
max-height: 27rem;
|
||||
|
||||
::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background-color: #c67e14;
|
||||
border: 2px solid #222;
|
||||
|
||||
&:hover {
|
||||
background-color: #e69419;
|
||||
}
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
color: #c67e14;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline solid 2px;
|
||||
}
|
||||
}
|
||||
|
||||
& > .title {
|
||||
// border-bottom: 2px solid #222;
|
||||
|
||||
border-top-left-radius: 9px;
|
||||
border-top-right-radius: 9px;
|
||||
|
||||
padding: 1rem;
|
||||
background: #f8e8b1;
|
||||
|
||||
font-family: 'Source Sans Pro', sans-serif;
|
||||
font-weight: 700;
|
||||
font-size: 32px;
|
||||
}
|
||||
& > .abstract {
|
||||
flex-grow: 1;
|
||||
|
||||
padding: 1rem;
|
||||
|
||||
overflow-y: auto;
|
||||
|
||||
@extend .text;
|
||||
}
|
||||
& > .continue {
|
||||
padding: 1rem;
|
||||
|
||||
display: grid;
|
||||
align-items: end;
|
||||
justify-content: end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[role='button'] {
|
||||
padding: 0.5rem 2rem;
|
||||
|
||||
&.primary {
|
||||
// background: #824ed4;
|
||||
// color: #f0e6ff;
|
||||
background: #f8e8b1;
|
||||
color: #000d;
|
||||
|
||||
&:hover {
|
||||
// background: #8e5ddd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
section.projects {
|
||||
background: #f5f2cc;
|
||||
|
||||
padding-bottom: 6rem;
|
||||
|
||||
.project-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
|
||||
gap: 3rem;
|
||||
|
||||
padding: 0 6rem;
|
||||
|
||||
align-items: start;
|
||||
|
||||
.project {
|
||||
// background: #fcddff;
|
||||
// background: #ffa89c;
|
||||
background: #a2d4f3;
|
||||
color: #000e;
|
||||
|
||||
border: 3px solid #222;
|
||||
border-radius: 9px;
|
||||
box-shadow: 9px 9px 0 0 #222;
|
||||
|
||||
padding: 1rem;
|
||||
|
||||
display: grid;
|
||||
grid-template-columns: auto 1fr;
|
||||
grid-template-rows: auto 1fr;
|
||||
|
||||
gap: 0.25rem 1rem;
|
||||
|
||||
.title {
|
||||
font-family: 'Source Sans Pro', sans-serif;
|
||||
font-weight: 700;
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.image {
|
||||
grid-row: span 2;
|
||||
// place-self: center;
|
||||
|
||||
.box {
|
||||
background: #0003;
|
||||
border: 3px solid #0006;
|
||||
border-radius: 6px;
|
||||
width: 5rem;
|
||||
height: 5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
transition: all 128ms ease-out;
|
||||
|
||||
&:hover {
|
||||
transform: translate(0, -8px);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
section.wanna-be-macchinista {
|
||||
background: #888;
|
||||
color: #fdfdfd;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Misc
|
||||
//
|
||||
|
||||
::-webkit-scrollbar-track:vertical {
|
||||
background-color: #f0f0f0;
|
||||
border-left: 2px solid #222;
|
||||
border-top: 2px solid #222;
|
||||
border-bottom: 2px solid #222;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track:horizontal {
|
||||
background-color: #f0f0f0;
|
||||
border-top: 2px solid #222;
|
||||
border-left: 2px solid #222;
|
||||
border-right: 2px solid #222;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background-color: #1e6733;
|
||||
border: 2px solid #222;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background-color: #2b8b47;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-corner {
|
||||
background-color: #f0f0f0;
|
||||
// border-left: 2px solid #222;
|
||||
// border-top: 2px solid #222;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar {
|
||||
width: 15px;
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"log"
|
||||
"os/exec"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/website/libs/db"
|
||||
"git.phc.dm.unipi.it/phc/website/libs/sl"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/website/server"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/website/server/config"
|
||||
"git.phc.dm.unipi.it/phc/website/server/database"
|
||||
"git.phc.dm.unipi.it/phc/website/server/listautenti"
|
||||
"git.phc.dm.unipi.it/phc/website/server/model"
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.SetFlags(0)
|
||||
}
|
||||
|
||||
func main() {
|
||||
l := sl.New()
|
||||
|
||||
//
|
||||
// Setup the application
|
||||
//
|
||||
|
||||
// Config
|
||||
sl.ProvideFunc(l, config.Slot, config.Configure)
|
||||
|
||||
// Database
|
||||
sl.Provide[database.Database](l, database.Slot, &database.Memory{
|
||||
Users: []model.User{
|
||||
{
|
||||
Id: "e39ad8d5-a087-4cb2-8fd7-5a6ca3f6a534",
|
||||
Username: "claire-doe",
|
||||
FullName: db.NewOption("Claire Doe"),
|
||||
Email: db.NewOption("claire.doe@example.org"),
|
||||
},
|
||||
{
|
||||
Id: "9b7109cd-95a1-41e9-a9f6-001a32c20ca1",
|
||||
Username: "john-smith",
|
||||
FullName: db.NewOption("John Smith"),
|
||||
Email: db.NewOption("john.smith@example.org"),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// Server
|
||||
sl.ProvideFunc(l, server.Slot, server.Configure)
|
||||
sl.ProvideHook(l, server.ApiRoutesHook,
|
||||
listautenti.MountApiRoutesHook,
|
||||
)
|
||||
|
||||
//
|
||||
// Start the application
|
||||
//
|
||||
|
||||
sl.MustInvoke(l, server.Slot)
|
||||
|
||||
r, w := io.Pipe()
|
||||
|
||||
cfg := sl.MustUse(l, config.Slot)
|
||||
|
||||
cmd := exec.Command(cfg.NpmCommand, "run", "dev")
|
||||
cmd.Stdout = w
|
||||
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
log.Printf(`[cmd/devserver] [vitejs] %s`, scanner.Text())
|
||||
}
|
||||
}()
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/website/libs/db"
|
||||
"git.phc.dm.unipi.it/phc/website/libs/sl"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/website/server"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/website/server/config"
|
||||
"git.phc.dm.unipi.it/phc/website/server/database"
|
||||
"git.phc.dm.unipi.it/phc/website/server/listautenti"
|
||||
"git.phc.dm.unipi.it/phc/website/server/model"
|
||||
)
|
||||
|
||||
func main() {
|
||||
l := sl.New()
|
||||
|
||||
//
|
||||
// Setup the application
|
||||
//
|
||||
|
||||
// Config
|
||||
sl.Provide(l, config.Slot, config.ExampleProductionConfig)
|
||||
|
||||
// Database
|
||||
sl.Provide[database.Database](l, database.Slot, &database.Memory{
|
||||
Users: []model.User{
|
||||
{
|
||||
Id: "e39ad8d5-a087-4cb2-8fd7-5a6ca3f6a534",
|
||||
Username: "claire-doe",
|
||||
FullName: db.NewOption("Claire Doe"),
|
||||
Email: db.NewOption("claire.doe@example.org"),
|
||||
},
|
||||
{
|
||||
Id: "9b7109cd-95a1-41e9-a9f6-001a32c20ca1",
|
||||
Username: "john-smith",
|
||||
FullName: db.NewOption("John Smith"),
|
||||
Email: db.NewOption("john.smith@example.org"),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// Server
|
||||
sl.ProvideFunc(l, server.Slot, server.Configure)
|
||||
sl.ProvideHook(l, server.ApiRoutesHook,
|
||||
listautenti.MountApiRoutesHook,
|
||||
)
|
||||
|
||||
//
|
||||
// Start the application
|
||||
//
|
||||
|
||||
err := sl.Invoke(l, server.Slot)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
module git.phc.dm.unipi.it/phc/website
|
||||
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/alecthomas/repr v0.2.0 // indirect
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/gofiber/fiber/v2 v2.44.0 // indirect
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/joho/godotenv v1.5.1 // indirect
|
||||
github.com/klauspost/compress v1.16.5 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.18 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||
github.com/philhofer/fwd v1.1.2 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 // indirect
|
||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
|
||||
github.com/tinylib/msgp v1.1.8 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.46.0 // indirect
|
||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
|
||||
golang.org/x/sys v0.7.0 // indirect
|
||||
gotest.tools v2.2.0+incompatible // indirect
|
||||
)
|
@ -0,0 +1,93 @@
|
||||
github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk=
|
||||
github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
|
||||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/gofiber/fiber/v2 v2.44.0 h1:Z90bEvPcJM5GFJnu1py0E1ojoerkyew3iiNJ78MQCM8=
|
||||
github.com/gofiber/fiber/v2 v2.44.0/go.mod h1:VTMtb/au8g01iqvHyaCzftuM/xmZgKOZCtFzz6CdV9w=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI=
|
||||
github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
|
||||
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
|
||||
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
|
||||
github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw=
|
||||
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
|
||||
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 h1:rmMl4fXJhKMNWl+K+r/fq4FbbKI+Ia2m9hYBLm2h4G4=
|
||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94/go.mod h1:90zrgN3D/WJsDd1iXHT96alCoN2KJo6/4x1DZC3wZs8=
|
||||
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4=
|
||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1AvpV+7XmhI4r39LGNzwUL4YpMuL5vk=
|
||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee/go.mod h1:qwtSXrKuJh/zsFQ12yEE89xfCrGKK63Rr7ctU/uCo4g=
|
||||
github.com/tinylib/msgp v1.1.6/go.mod h1:75BAfg2hauQhs3qedfdDZmWAPcFMAvJE5b9rGOMufyw=
|
||||
github.com/tinylib/msgp v1.1.8 h1:FCXC1xanKO4I8plpHGH2P7koL/RzZs12l/+r7vakfm0=
|
||||
github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.46.0 h1:6ZRhrFg8zBXTRYY6vdzbFhqsBd7FVv123pV2m9V87U4=
|
||||
github.com/valyala/fasthttp v1.46.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
|
||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
|
||||
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
|
||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
|
||||
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
@ -0,0 +1,250 @@
|
||||
// This package provides a small framework to work with SQL databases using
|
||||
// generics. The most important part for now is the "Ref[T]" type that lets
|
||||
// us pass around typed IDs to table rows in a type safe manner.
|
||||
//
|
||||
// For now this library uses both generics for keeping the interface type safe
|
||||
// and reflection to extract automatically some metedata from structs that
|
||||
// represent tables.
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
// Option è un valore che nel database può potenzialmente essere "NULL"
|
||||
//
|
||||
// NOTE/TODO: Magari si può fare una cosa fatta bene e nascondere
|
||||
// l'implementazione al Go, ad esempio Option[string] può essere NULL o testo
|
||||
// nel db mentre Option[time.Time] può essere codificato in json come
|
||||
//
|
||||
// "{ present: false }"
|
||||
//
|
||||
// oppure
|
||||
//
|
||||
// "{ present: true, value: '2023/04/...' }"
|
||||
//
|
||||
// in modo da semplificare leggermente la processazione in Go. Altrimenti si
|
||||
// può separare in Option[T] e Nullable[T].
|
||||
type Option[T any] struct {
|
||||
present bool
|
||||
value T
|
||||
}
|
||||
|
||||
func (o Option[T]) MarshalJSON() ([]byte, error) {
|
||||
if !o.present {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
|
||||
return json.Marshal(o.value)
|
||||
}
|
||||
|
||||
func (o Option[T]) UnmarshalJSON(v []byte) error {
|
||||
if slices.Equal(v, []byte("null")) {
|
||||
var zero T
|
||||
o.present = false
|
||||
o.value = zero
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(v, &o.value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewOption[T any](value T) Option[T] {
|
||||
return Option[T]{true, value}
|
||||
}
|
||||
|
||||
func NewEmptyOption[T any]() Option[T] {
|
||||
return Option[T]{present: false}
|
||||
}
|
||||
|
||||
func (Option[T]) SqlType() string {
|
||||
return "BLOB"
|
||||
}
|
||||
|
||||
// func (v *Option[T]) Scan(a any) error {
|
||||
// data, ok := a.([]byte)
|
||||
// if !ok {
|
||||
// return fmt.Errorf(`scan expected []byte`)
|
||||
// }
|
||||
|
||||
// m := map[string]any{}
|
||||
// if err := json.Unmarshal(data, m); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if present, _ := m["present"].(bool); present {
|
||||
|
||||
// m["value"]
|
||||
// }
|
||||
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// Ref è un id tipato da un'entità presente nel database. È il tipo fondamentale
|
||||
// esportato da questo package. Non dovrebbe essere troppo importante ma
|
||||
// internamente è una stringa, inoltre è consigliato che una struct
|
||||
// con _primary key_ abbia un campo di tipo Ref a se stessa.
|
||||
//
|
||||
// type User struct {
|
||||
// Id db.Ref[User] // meglio se unico e immutabile
|
||||
// ...
|
||||
// }
|
||||
type Ref[T any] string
|
||||
|
||||
func (Ref[T]) SqlType() string {
|
||||
return "TEXT"
|
||||
}
|
||||
|
||||
func (v *Ref[T]) Scan(a any) error {
|
||||
s, ok := a.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf(`scan expected string`)
|
||||
}
|
||||
|
||||
*v = Ref[T](s)
|
||||
return nil
|
||||
}
|
||||
|
||||
type sqlValue interface {
|
||||
SqlType() string
|
||||
sql.Scanner
|
||||
}
|
||||
|
||||
type Table[T any] struct {
|
||||
Name string
|
||||
PrimaryKey func(value *T, pk ...string) Ref[T]
|
||||
Columns [][2]string
|
||||
}
|
||||
|
||||
var commonTypes = map[string]string{
|
||||
"string": "TEXT",
|
||||
"int": "INTEGER",
|
||||
"int32": "INTEGER",
|
||||
"int64": "INTEGER",
|
||||
"float32": "REAL",
|
||||
"float64": "REAL",
|
||||
}
|
||||
|
||||
func toSqlType(typ reflect.Type) string {
|
||||
st, ok := reflect.New(typ).Interface().(sqlValue)
|
||||
if ok {
|
||||
return st.SqlType()
|
||||
}
|
||||
|
||||
return commonTypes[typ.Name()]
|
||||
}
|
||||
|
||||
func AutoTable[T any](name string) Table[T] {
|
||||
columns := [][2]string{}
|
||||
pkIndex := -1
|
||||
|
||||
var zero T
|
||||
typ := reflect.TypeOf(zero)
|
||||
for i := 0; i < typ.NumField(); i++ {
|
||||
fieldTyp := typ.Field(i)
|
||||
isPK, _, typ, col := fieldInfo(fieldTyp)
|
||||
if isPK {
|
||||
pkIndex = i
|
||||
}
|
||||
columns = append(columns, [2]string{col, toSqlType(typ)})
|
||||
}
|
||||
|
||||
if pkIndex == -1 {
|
||||
panic(fmt.Sprintf("struct %T has no primary key field", zero))
|
||||
}
|
||||
|
||||
// debug logging
|
||||
// log.Printf("[auto table] struct %T has primary key %q", zero, typ.Field(pkIndex).Name)
|
||||
|
||||
return Table[T]{
|
||||
Name: name,
|
||||
PrimaryKey: func(value *T, pk ...string) Ref[T] {
|
||||
// SAFETY: this is required to cast *Ref[T] to *string, internally
|
||||
// they are the same type so this should be safe
|
||||
ptr := reflect.ValueOf(value).Elem().Field(pkIndex).Addr().UnsafePointer()
|
||||
pkPtr := (*string)(ptr)
|
||||
|
||||
if len(pk) > 0 {
|
||||
*pkPtr = pk[0]
|
||||
}
|
||||
|
||||
return Ref[T](*pkPtr)
|
||||
},
|
||||
Columns: columns,
|
||||
}
|
||||
}
|
||||
|
||||
func (table Table[T]) CreateIfNotExists(dbConn *sql.DB) error {
|
||||
columns := make([]string, len(table.Columns))
|
||||
|
||||
for i, col := range table.Columns {
|
||||
columns[i] = fmt.Sprintf("%s %s", col[0], col[1])
|
||||
}
|
||||
|
||||
stmt := fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %s(%s)`,
|
||||
table.Name,
|
||||
strings.Join(columns, ", "),
|
||||
)
|
||||
|
||||
_, err := dbConn.Exec(stmt)
|
||||
return err
|
||||
}
|
||||
|
||||
func Create[T any](dbConn *sql.DB, table Table[T], value T) (Ref[T], error) {
|
||||
id := randomHex(15)
|
||||
|
||||
table.PrimaryKey(&value, id)
|
||||
|
||||
columns, values := structDatabaseColumnValues(&value)
|
||||
|
||||
stmt := fmt.Sprintf(`INSERT INTO %s(%s) VALUES (%s)`,
|
||||
table.Name,
|
||||
strings.Join(columns, ", "),
|
||||
strings.Join(repeatSlice("?", len(columns)), ", "),
|
||||
)
|
||||
|
||||
if _, err := dbConn.Exec(stmt, values...); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return Ref[T](id), nil
|
||||
}
|
||||
|
||||
func Insert[T any](dbConn *sql.DB, table Table[T], value T) error {
|
||||
columns, values := structDatabaseColumnValues(&value)
|
||||
|
||||
stmt := fmt.Sprintf(`INSERT INTO %s(%s) VALUES (%s)`,
|
||||
table.Name,
|
||||
strings.Join(columns, ", "),
|
||||
strings.Join(repeatSlice("?", len(columns)), ", "),
|
||||
)
|
||||
|
||||
_, err := dbConn.Exec(stmt, values...)
|
||||
return err
|
||||
}
|
||||
|
||||
func Read[T any](dbConn *sql.DB, table Table[T], id Ref[T]) (T, error) {
|
||||
panic("todo")
|
||||
}
|
||||
|
||||
func ReadAll[T any](dbConn *sql.DB, table Table[T]) ([]T, error) {
|
||||
panic("todo")
|
||||
}
|
||||
|
||||
func Update[T any](dbConn *sql.DB, table Table[T], id Ref[T], value T) error {
|
||||
panic("todo")
|
||||
}
|
||||
|
||||
func Delete[T any](dbConn *sql.DB, table Table[T], id Ref[T]) error {
|
||||
panic("todo")
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package db_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"testing"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/website/libs/db"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
type mockDB struct {
|
||||
*testing.T
|
||||
|
||||
LastQuery string
|
||||
}
|
||||
|
||||
func (db *mockDB) Prepare(query string) (driver.Stmt, error) { return nil, nil }
|
||||
func (db *mockDB) Close() error { return nil }
|
||||
func (db *mockDB) Begin() (driver.Tx, error) { return nil, nil }
|
||||
|
||||
func (db *mockDB) Query(query string, args []driver.Value) (driver.Rows, error) {
|
||||
db.LastQuery = query
|
||||
db.Logf("[sql mock driver] [exec] query: '%s', args: %#v", query, args)
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (db *mockDB) Exec(query string, args []driver.Value) (driver.Result, error) {
|
||||
db.LastQuery = query
|
||||
db.Logf("[sql mock driver] [exec] query: '%s', args: %#v", query, args)
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (db *mockDB) Open(name string) (driver.Conn, error) {
|
||||
return &mockDB{T: db.T}, nil
|
||||
}
|
||||
|
||||
func (db *mockDB) Connect(context.Context) (driver.Conn, error) {
|
||||
return db, nil
|
||||
}
|
||||
|
||||
func (db *mockDB) Driver() driver.Driver {
|
||||
return db
|
||||
}
|
||||
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
|
||||
func TestDb1(t *testing.T) {
|
||||
type Product struct {
|
||||
Id db.Ref[Product] `db:"id*"`
|
||||
Title string `db:"title"`
|
||||
Quantity int `db:"quantity"`
|
||||
}
|
||||
|
||||
products := db.AutoTable[Product]("products")
|
||||
|
||||
mock := &mockDB{T: t}
|
||||
conn := sql.OpenDB(mock)
|
||||
|
||||
err := products.CreateIfNotExists(conn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, mock.LastQuery,
|
||||
`CREATE TABLE IF NOT EXISTS products(id TEXT, title TEXT, quantity INTEGER)`,
|
||||
)
|
||||
|
||||
ref1, err := db.Create(conn, products, Product{Title: "Foo", Quantity: 27})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Assert(t, string(ref1) != "")
|
||||
assert.Equal(t, mock.LastQuery,
|
||||
`INSERT INTO products(id, title, quantity) VALUES (?, ?, ?)`,
|
||||
)
|
||||
|
||||
if err := db.Insert(conn, products, Product{Id: "123", Title: "Bar", Quantity: 42}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, mock.LastQuery,
|
||||
`INSERT INTO products(id, title, quantity) VALUES (?, ?, ?)`,
|
||||
)
|
||||
}
|
@ -0,0 +1 @@
|
||||
package db
|
@ -0,0 +1,118 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func randomHex(len int) string {
|
||||
buff := make([]byte, len/2+1)
|
||||
rand.Read(buff)
|
||||
str := hex.EncodeToString(buff)
|
||||
return str[:len]
|
||||
}
|
||||
|
||||
func fieldInfo(fieldTyp reflect.StructField) (bool, string, reflect.Type, string) {
|
||||
fieldName := fieldTyp.Name
|
||||
columnName, ok := fieldTyp.Tag.Lookup("db")
|
||||
if !ok {
|
||||
columnName = strings.ToLower(fieldName)
|
||||
}
|
||||
if ok && columnName[len(columnName)-1] == '*' {
|
||||
return true, fieldName, fieldTyp.Type, columnName[:len(columnName)-1]
|
||||
}
|
||||
|
||||
return false, fieldName, fieldTyp.Type, columnName
|
||||
}
|
||||
|
||||
func fieldPrimaryKey(fieldTyp reflect.StructField) bool {
|
||||
isPK, _, _, _ := fieldInfo(fieldTyp)
|
||||
return isPK
|
||||
}
|
||||
|
||||
// structDatabaseColumnValues takes a pointer to a struct and returns a pair
|
||||
// of slices, one with the column names and the other with pointers to all
|
||||
// its exported fields.
|
||||
//
|
||||
// The column name can be changed using the "db" tag attribute on that field
|
||||
func structDatabaseColumnValues(s any) ([]string, []any) {
|
||||
v := reflect.ValueOf(s).Elem()
|
||||
|
||||
numFields := v.NumField()
|
||||
|
||||
names := []string{}
|
||||
values := []any{}
|
||||
|
||||
for i := 0; i < numFields; i++ {
|
||||
fieldTyp := v.Type().Field(i)
|
||||
fieldVal := v.Field(i)
|
||||
|
||||
if fieldTyp.IsExported() {
|
||||
key := strings.ToLower(fieldTyp.Name)
|
||||
|
||||
if name, ok := fieldTyp.Tag.Lookup("db"); ok {
|
||||
key = name
|
||||
|
||||
// primary key has a "*" at the end, exclude from column name
|
||||
if key[len(key)-1] == '*' {
|
||||
key = key[:len(key)-1]
|
||||
}
|
||||
}
|
||||
|
||||
names = append(names, key)
|
||||
values = append(values, fieldVal.Addr().Interface())
|
||||
}
|
||||
}
|
||||
|
||||
return names, values
|
||||
}
|
||||
|
||||
func structPrimaryKeyPtr(s any) (*string, bool) {
|
||||
v := reflect.ValueOf(s).Elem()
|
||||
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
fieldTyp := v.Type().Field(i)
|
||||
fieldVal := v.Field(i)
|
||||
|
||||
if fieldTyp.IsExported() {
|
||||
if fieldPrimaryKey(fieldTyp) {
|
||||
// SAFETY: this is required to cast *Ref[T] to *string, internally
|
||||
// they are the same type so this should be safe
|
||||
ptr := fieldVal.Addr().UnsafePointer()
|
||||
return (*string)(ptr), true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// structDatabasePrimaryKeyColumn takes a pointer to a struct and returns the
|
||||
// name of the field with the primary key
|
||||
func structDatabasePrimaryKeyColumn(s any) (field, column string, ok bool) {
|
||||
v := reflect.ValueOf(s).Elem()
|
||||
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
fieldTyp := v.Type().Field(i)
|
||||
if fieldTyp.IsExported() {
|
||||
key := fieldTyp.Name
|
||||
if value, ok := fieldTyp.Tag.Lookup("db"); ok {
|
||||
if value[len(value)-1] == '*' {
|
||||
return key, value[:len(value)-1], true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "", "", false
|
||||
}
|
||||
|
||||
func repeatSlice[T any](value T, count int) []T {
|
||||
s := make([]T, count)
|
||||
for i := 0; i < count; i++ {
|
||||
s[i] = value
|
||||
}
|
||||
return s
|
||||
}
|
@ -0,0 +1,277 @@
|
||||
// The [sl] package has two main concepts, the [ServiceLocator] itself is the
|
||||
// main object that one should pass around through the application. A
|
||||
// [ServiceLocator] has a list of slots that can be filled with
|
||||
// [ProvideFunc] and [Provide] and retrieved with [Use]. Slots should
|
||||
// be unique by type and they can only be created with the [NewSlot] function.
|
||||
//
|
||||
// The usual way to use this module is to make slots for Go interfaces and
|
||||
// then pass implementations using the [Provide] and
|
||||
// [ProvideFunc] functions.
|
||||
//
|
||||
// Services can be of various types:
|
||||
// - a service with no dependencies can be directly injected inside a
|
||||
// ServiceLocator using [Provide].
|
||||
// - a service with dependencies on other service should use
|
||||
// [ProvideFunc]. This lets the service configure itself when needed
|
||||
// and makes the developer not think about correctly ordering the
|
||||
// recursive configuration of its dependencies.
|
||||
// - a service can also be private, in this case the slot for a service
|
||||
// should be a private field in the service package. This kind of
|
||||
// services should also provide a way to inject them into a
|
||||
// ServiceLocator.
|
||||
// - a package can also just provide a slot with some value. This is useful
|
||||
// for using the ServiceLocator to easily pass around values, effectively
|
||||
// threating slots just as dynamically scoped variables.
|
||||
package sl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Logger is the debug logger
|
||||
//
|
||||
// TODO: in the future this will be disabled and discard by default.
|
||||
//
|
||||
// As this is the service locator module it was meaning less to pass this
|
||||
// through the ServiceLocator itself (without making the whole module more
|
||||
// complex)
|
||||
var Logger *log.Logger = log.New(os.Stderr, "[service locator] ", log.Lmsgprefix)
|
||||
|
||||
// slot is just a "typed" unique "symbol".
|
||||
//
|
||||
// This must be defined like so and not for example "struct{ typeName string }"
|
||||
// because we might want to have more slots for the same type.
|
||||
type slot[T any] *struct{}
|
||||
|
||||
type Hook[T any] func(*ServiceLocator, T) error
|
||||
|
||||
// hook is just a typed unique symbol
|
||||
type hook[T any] *struct{}
|
||||
|
||||
// NewSlot is the only way to create instances of the slot type. Each instance
|
||||
// is unique.
|
||||
//
|
||||
// This then lets you attach a service instance of type "T" to a
|
||||
// [ServiceLocator] object.
|
||||
func NewSlot[T any]() slot[T] {
|
||||
return slot[T](new(struct{}))
|
||||
}
|
||||
|
||||
// NewHook is the only way to create instances of the hook type. Each instance
|
||||
// is unique.
|
||||
//
|
||||
// This lets you have a service dispatch an hook
|
||||
func NewHook[T any]() hook[T] {
|
||||
return hook[T](new(struct{}))
|
||||
}
|
||||
|
||||
// slotEntry represents a service that can lazily configured
|
||||
// (using "configureFunc"). Once configured the instance is kept in the "value"
|
||||
// field and "created" will always be "true". The field "typeName" just for
|
||||
// debugging purposes.
|
||||
type slotEntry struct {
|
||||
// typeName is just used for debugging purposes
|
||||
typeName string
|
||||
|
||||
// configureFunc is used by lazily provided slot values to tell how to
|
||||
// configure them self when required
|
||||
configureFunc func(*ServiceLocator) (any, error)
|
||||
|
||||
// configured tells if this slot is already configured
|
||||
configured bool
|
||||
|
||||
// value for this slot
|
||||
value any
|
||||
}
|
||||
|
||||
// checkConfigured tries to call configure on this slot entry if not already configured
|
||||
func (s *slotEntry) checkConfigured(l *ServiceLocator) error {
|
||||
if !s.configured {
|
||||
v, err := s.configureFunc(l)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Logger.Printf(`[slot: %s] configured service of type %T`, s.typeName, v)
|
||||
|
||||
s.configured = true
|
||||
s.value = v
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type hookEntry struct {
|
||||
// typeName is just used for debugging purposes
|
||||
typeName string
|
||||
|
||||
// listeners is a list of functions to call when this hook is called
|
||||
listeners []func(*ServiceLocator, any) error
|
||||
}
|
||||
|
||||
// ServiceLocator is the main context passed around to retrive service
|
||||
// instances, the interface uses generics so to inject and retrive service
|
||||
// instances you should use the functions [Provide], [ProvideFunc] and [Use].
|
||||
// This is essentially a dictionary indexed by slots that are them self just
|
||||
// typed unique symbols
|
||||
type ServiceLocator struct {
|
||||
providers map[any]*slotEntry
|
||||
hooks map[any]*hookEntry
|
||||
}
|
||||
|
||||
// New creates a new [ServiceLocator] context to pass around in the application.
|
||||
func New() *ServiceLocator {
|
||||
return &ServiceLocator{
|
||||
providers: map[any]*slotEntry{},
|
||||
hooks: map[any]*hookEntry{},
|
||||
}
|
||||
}
|
||||
|
||||
// Provide will inject a concrete instance inside the ServiceLocator "l" for
|
||||
// the given "slotKey". This should be used for injecting "static" services, for
|
||||
// instances whose construction depend on other services you should use the
|
||||
// [ProvideFunc] function.
|
||||
//
|
||||
// This is generic over "T" to check that instances for the given slot type
|
||||
// check as "T" can also be an interface.
|
||||
func Provide[T any](l *ServiceLocator, slotKey slot[T], value T) T {
|
||||
typeName := getTypeName[T]()
|
||||
|
||||
Logger.Printf(`[slot: %s] provided value of type %T`, typeName, value)
|
||||
|
||||
l.providers[slotKey] = &slotEntry{
|
||||
typeName: typeName,
|
||||
configured: true,
|
||||
value: value,
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// ProvideFunc will inject an instance inside the given ServiceLocator
|
||||
// and "slotKey" that is created only when requested with a call to the
|
||||
// [Use] function.
|
||||
//
|
||||
// This is generic over "T" to check that instances for the given slot type
|
||||
// check as "T" can also be an interface.
|
||||
func ProvideFunc[T any](l *ServiceLocator, slotKey slot[T], createFunc func(*ServiceLocator) (T, error)) {
|
||||
typeName := getTypeName[T]()
|
||||
Logger.Printf(`[slot: %s] inject lazy provider`, typeName)
|
||||
|
||||
l.providers[slotKey] = &slotEntry{
|
||||
typeName: typeName,
|
||||
configureFunc: func(l *ServiceLocator) (any, error) { return createFunc(l) },
|
||||
configured: false,
|
||||
}
|
||||
}
|
||||
|
||||
// Use retrieves the value of type T associated with the given slot key from
|
||||
// the provided ServiceLocator instance.
|
||||
//
|
||||
// If the ServiceLocator does not have a value for the slot key, or if the
|
||||
// value wasn't correctly configured (in the case of a lazy slot), an error
|
||||
// is returned.
|
||||
func Use[T any](l *ServiceLocator, slotKey slot[T]) (T, error) {
|
||||
var zero T
|
||||
|
||||
slot, ok := l.providers[slotKey]
|
||||
if !ok {
|
||||
return zero, fmt.Errorf(`no injected value for type %s`, getTypeName[T]())
|
||||
}
|
||||
|
||||
err := slot.checkConfigured(l)
|
||||
if err != nil {
|
||||
return zero, err
|
||||
}
|
||||
|
||||
v := slot.value.(T)
|
||||
|
||||
Logger.Printf(`[slot: %s] using slot with value of type %T`, getTypeName[T](), v)
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func MustUse[T any](l *ServiceLocator, slotKey slot[T]) T {
|
||||
v, err := Use(l, slotKey)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
func Invoke[T any](l *ServiceLocator, slotKey slot[T]) error {
|
||||
slot, ok := l.providers[slotKey]
|
||||
if !ok {
|
||||
return fmt.Errorf(`no injected value for type %s`, getTypeName[T]())
|
||||
}
|
||||
|
||||
err := slot.checkConfigured(l)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
v := slot.value.(T)
|
||||
|
||||
Logger.Printf(`[slot: %s] invoked slot with value of type %T`, getTypeName[T](), v)
|
||||
return nil
|
||||
}
|
||||
|
||||
func MustInvoke[T any](l *ServiceLocator, slotKey slot[T]) {
|
||||
if err := Invoke(l, slotKey); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func ProvideHook[T any](l *ServiceLocator, hookKey hook[T], listeners ...Hook[T]) {
|
||||
typeName := getTypeName[T]()
|
||||
Logger.Printf(`[hook: %s] injecting hooks`, typeName)
|
||||
|
||||
// cast type safe listeners to internal untyped version to put inside the hook map
|
||||
anyListeners := make([]func(*ServiceLocator, any) error, len(listeners))
|
||||
for i, l := range listeners {
|
||||
ll := l
|
||||
anyListeners[i] = func(l *ServiceLocator, a any) error {
|
||||
t, ok := a.(T)
|
||||
if !ok {
|
||||
panic(`illegal state`)
|
||||
}
|
||||
|
||||
return ll(l, t)
|
||||
}
|
||||
}
|
||||
|
||||
l.hooks[hookKey] = &hookEntry{
|
||||
typeName: typeName,
|
||||
listeners: anyListeners,
|
||||
}
|
||||
}
|
||||
|
||||
func UseHook[T any](l *ServiceLocator, hookKey hook[T], value T) error {
|
||||
hookEntry, ok := l.hooks[hookKey]
|
||||
if !ok {
|
||||
return fmt.Errorf(`no injected hooks for hook of type %s`, hookEntry.typeName)
|
||||
}
|
||||
|
||||
Logger.Printf(`[hook: %s] calling hook with value of type %T`, hookEntry.typeName, value)
|
||||
for _, hookFunc := range hookEntry.listeners {
|
||||
if err := hookFunc(l, value); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func MustUseHook[T any](l *ServiceLocator, hookKey hook[T], value T) {
|
||||
if err := UseHook(l, hookKey, value); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// getTypeName is a trick to get the name of a type (even if it is an
|
||||
// interface type)
|
||||
func getTypeName[T any]() string {
|
||||
var zero T
|
||||
return fmt.Sprintf(`%T`, &zero)[1:]
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// CompactIndentedLines removes all indentation from a string and also removes all newlines, usefull in tests
|
||||
func CompactIndentedLines(s string) string {
|
||||
return regexp.MustCompile(`(?m)\n\s+`).ReplaceAllString(s, "")
|
||||
}
|
@ -1,51 +1,23 @@
|
||||
{
|
||||
"name": "website",
|
||||
"type": "module",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"dev": "run-s astro:sync astro:dev",
|
||||
"build": "run-s astro:build",
|
||||
"astro:sync": "astro sync",
|
||||
"astro:dev": "astro dev",
|
||||
"astro:build": "astro check && astro build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/check": "^0.9.4",
|
||||
"@astrojs/node": "9.0.0",
|
||||
"@astrojs/preact": "4.0.0",
|
||||
"@fontsource-variable/material-symbols-outlined": "^5.1.1",
|
||||
"@fontsource/iosevka": "^5.0.11",
|
||||
"@fontsource/mononoki": "^5.0.11",
|
||||
"@fontsource/open-sans": "^5.0.24",
|
||||
"@fontsource/source-code-pro": "^5.0.16",
|
||||
"@fontsource/source-sans-pro": "^5.0.8",
|
||||
"@fontsource/space-mono": "^5.0.20",
|
||||
"@phosphor-icons/core": "^2.1.1",
|
||||
"@phosphor-icons/react": "^2.1.7",
|
||||
"@preact/signals": "^1.3.0",
|
||||
"@types/jsdom": "^21.1.7",
|
||||
"astro": "5.1.0",
|
||||
"fuse.js": "^7.0.0",
|
||||
"katex": "^0.16.9",
|
||||
"lucide-static": "^0.468.0",
|
||||
"marked": "^15.0.6",
|
||||
"preact": "^10.19.6",
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@astrojs/mdx": "4.0.2",
|
||||
"@rollup/plugin-yaml": "^4.1.2",
|
||||
"@types/katex": "^0.16.7",
|
||||
"jsdom": "^24.1.1",
|
||||
"linkedom": "^0.18.4",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prettier": "^3.5.0",
|
||||
"prettier-plugin-astro": "^0.14.1",
|
||||
"rehype-autolink-headings": "^7.1.0",
|
||||
"rehype-slug": "^6.0.0",
|
||||
"remark-math": "^6.0.0",
|
||||
"remark-toc": "^9.0.0",
|
||||
"sass": "^1.71.1",
|
||||
"tsx": "^4.7.1"
|
||||
}
|
||||
"name": "website-frontend",
|
||||
"version": "1.0.0",
|
||||
"description": "Frontend for the PHC website",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "astro dev",
|
||||
"start": "astro dev",
|
||||
"build": "astro build",
|
||||
"preview": "astro preview"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@fontsource/open-sans": "^4.5.14",
|
||||
"@fontsource/source-code-pro": "^4.5.14",
|
||||
"@fontsource/source-sans-pro": "^4.5.11",
|
||||
"astro": "^2.3.1",
|
||||
"sass": "^1.62.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.0.4"
|
||||
}
|
||||
}
|
||||
|
@ -1,95 +0,0 @@
|
||||
<svg width="1000" height="500" viewBox="0 0 1000 500" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect x="80" y="190" width="60" height="120" fill="#1E6733" />
|
||||
<rect x="160" y="50" width="150" height="60" fill="#1E6733" />
|
||||
<rect x="140" y="90" width="10" height="50" fill="#ECC333" />
|
||||
<rect x="140" y="200" width="10" height="50" fill="#ECC333" />
|
||||
<rect x="140" y="410" width="10" height="20" fill="#ECC333" />
|
||||
<rect x="140" y="350" width="10" height="50" fill="#ECC333" />
|
||||
<rect x="240" y="110" width="70" height="10" fill="#ECC333" />
|
||||
<rect x="250" y="130" width="60" height="130" fill="#1E6733" />
|
||||
<rect x="340" y="50" width="60" height="120" fill="#1E6733" />
|
||||
<rect x="340" y="190" width="60" height="120" fill="#1E6733" />
|
||||
<rect x="590" y="190" width="60" height="120" fill="#1E6733" />
|
||||
<rect x="690" y="180" width="60" height="120" fill="#1E6733" />
|
||||
<rect x="690" y="310" width="60" height="140" fill="#1E6733" />
|
||||
<rect x="690" y="50" width="60" height="120" fill="#1E6733" />
|
||||
<rect x="590" y="320" width="60" height="130" fill="#1E6733" />
|
||||
<rect x="590" y="50" width="60" height="130" fill="#1E6733" />
|
||||
<rect x="420" y="240" width="150" height="60" fill="#1E6733" />
|
||||
<rect x="340" y="320" width="60" height="130" fill="#1E6733" />
|
||||
<rect x="240" y="140" width="10" height="50" fill="#ECC333" />
|
||||
<rect x="350" y="170" width="40" height="10" fill="#ECC333" />
|
||||
<rect x="330" y="330" width="10" height="50" fill="#ECC333" />
|
||||
<rect x="160" y="200" width="80" height="60" fill="#1E6733" />
|
||||
<rect x="650" y="200" width="10" height="50" fill="#ECC333" />
|
||||
<rect x="750" y="330" width="10" height="60" fill="#ECC333" />
|
||||
<rect x="800" y="450" width="40" height="10" fill="#ECC333" />
|
||||
<rect x="850" y="450" width="30" height="10" fill="#ECC333" />
|
||||
<rect x="750" y="90" width="10" height="50" fill="#ECC333" />
|
||||
<rect x="810" y="110" width="60" height="10" fill="#ECC333" />
|
||||
<rect x="580" y="330" width="10" height="50" fill="#ECC333" />
|
||||
<rect x="580" y="60" width="10" height="50" fill="#ECC333" />
|
||||
<rect x="710" y="420" width="20" height="20" fill="#C4C4C4" />
|
||||
<rect x="710" y="390" width="20" height="20" fill="#C4C4C4" />
|
||||
<rect x="100" y="280" width="20" height="10" fill="#C4C4C4" />
|
||||
<rect x="100" y="260" width="20" height="10" fill="#C4C4C4" />
|
||||
<rect x="110" y="210" width="20" height="20" fill="#C4C4C4" />
|
||||
<rect x="350" y="430" width="40" height="10" fill="#303030" />
|
||||
<rect x="350" y="410" width="40" height="10" fill="#303030" />
|
||||
<rect x="350" y="390" width="40" height="10" fill="#303030" />
|
||||
<rect x="700" y="70" width="20" height="40" fill="#303030" />
|
||||
<rect x="700" y="120" width="20" height="40" fill="#303030" />
|
||||
<rect x="610" y="280" width="20" height="20" fill="#C4C4C4" />
|
||||
<rect x="600" y="240" width="20" height="20" fill="#C4C4C4" />
|
||||
<rect x="430" y="250" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="430" y="265" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="430" y="280" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="445" y="250" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="445" y="265" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="460" y="280" width="40" height="10" fill="#C4C4C4" />
|
||||
<rect x="475" y="250" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="475" y="265" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="505" y="250" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="505" y="265" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="520" y="265" width="10" height="15" fill="#C4C4C4" />
|
||||
<rect x="505" y="280" width="25" height="10" fill="#C4C4C4" />
|
||||
<rect x="535" y="250" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="535" y="265" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="535" y="280" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="445" y="280" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="460" y="250" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="460" y="265" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="490" y="250" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="490" y="265" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="520" y="250" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="550" y="250" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="550" y="265" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="550" y="280" width="10" height="10" fill="#C4C4C4" />
|
||||
<rect x="620" y="210" width="20" height="20" fill="#C4C4C4" />
|
||||
<rect x="370" y="70" width="20" height="30" fill="#303030" />
|
||||
<rect x="370" y="110" width="20" height="30" fill="#303030" />
|
||||
<rect x="870" y="440" width="40" height="10" transform="rotate(-90 870 440)" fill="#303030" />
|
||||
<rect x="890" y="440" width="40" height="10" transform="rotate(-90 890 440)" fill="#303030" />
|
||||
<rect x="810" y="440" width="40" height="10" transform="rotate(-90 810 440)" fill="#303030" />
|
||||
<rect x="790" y="440" width="40" height="10" transform="rotate(-90 790 440)" fill="#303030" />
|
||||
<rect x="270" y="100" width="40" height="10" transform="rotate(-90 270 100)" fill="#303030" />
|
||||
<rect x="290" y="100" width="40" height="10" transform="rotate(-90 290 100)" fill="#303030" />
|
||||
<rect x="190" y="100" width="40" height="10" transform="rotate(-90 190 100)" fill="#303030" />
|
||||
<rect x="170" y="100" width="40" height="10" transform="rotate(-90 170 100)" fill="#303030" />
|
||||
<path fill-rule="evenodd" clip-rule="evenodd"
|
||||
d="M140 60V170C134.477 170 130 174.477 130 180H90C90 174.477 85.5228 170 80 170V60C85.5228 60 90 55.5228 90 50H130C130 55.5228 134.477 60 140 60Z"
|
||||
fill="#1E6733" />
|
||||
<path fill-rule="evenodd" clip-rule="evenodd"
|
||||
d="M130 320H90C90 325.523 85.5229 330 80 330V440C85.5229 440 90 444.477 90 450H130C130 444.477 134.477 440 140 440V330C134.477 330 130 325.523 130 320Z"
|
||||
fill="#1E6733" />
|
||||
<path fill-rule="evenodd" clip-rule="evenodd"
|
||||
d="M770 60C775.523 60 780 55.5228 780 50H910C910 55.5228 914.477 60 920 60V100C914.477 100 910 104.477 910 110H780C780 104.477 775.523 100 770 100V60Z"
|
||||
fill="#1E6733" />
|
||||
<path fill-rule="evenodd" clip-rule="evenodd"
|
||||
d="M770 400C775.523 400 780 395.523 780 390H910C910 395.523 914.477 400 920 400V440C914.477 440 910 444.477 910 450H780C780 444.477 775.523 440 770 440V400Z"
|
||||
fill="#1E6733" />
|
||||
<rect x="750" y="190" width="10" height="40" fill="#ECC333" />
|
||||
<rect x="750" y="240" width="10" height="20" fill="#ECC333" />
|
||||
<rect x="400" y="200" width="10" height="40" fill="#ECC333" />
|
||||
<rect x="400" y="250" width="10" height="20" fill="#ECC333" />
|
||||
</svg>
|
Before Width: | Height: | Size: 6.6 KiB |
Before Width: | Height: | Size: 82 KiB |
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 3.5 KiB |
@ -0,0 +1,54 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"git.phc.dm.unipi.it/phc/website/libs/sl"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Mode string
|
||||
Host string
|
||||
|
||||
NpmCommand string
|
||||
}
|
||||
|
||||
var Slot = sl.NewSlot[Config]()
|
||||
|
||||
func setFromEnvOrDefault(target *string, m map[string]string, key string, defaultValue string) {
|
||||
v, ok := m[key]
|
||||
if ok {
|
||||
*target = v
|
||||
} else {
|
||||
*target = defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
func Configure(l *sl.ServiceLocator) (Config, error) {
|
||||
env, err := godotenv.Read(".env")
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
var cfg Config
|
||||
|
||||
setFromEnvOrDefault(&cfg.Mode, env, "MODE", "production")
|
||||
setFromEnvOrDefault(&cfg.Host, env, "HOST", ":4000")
|
||||
setFromEnvOrDefault(&cfg.NpmCommand, env, "NPM_COMMAND", "npm")
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
var ExampleProductionConfig = Config{
|
||||
Mode: "production",
|
||||
Host: ":4000",
|
||||
|
||||
NpmCommand: "npm",
|
||||
}
|
||||
|
||||
var ExampleDevelopmentConfig = Config{
|
||||
Mode: "development",
|
||||
Host: ":4000",
|
||||
|
||||
NpmCommand: "npm",
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/website/libs/db"
|
||||
"git.phc.dm.unipi.it/phc/website/libs/sl"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/website/server/model"
|
||||
)
|
||||
|
||||
var Slot = sl.NewSlot[Database]()
|
||||
|
||||
// Database is the main database service interface
|
||||
type Database interface {
|
||||
// User
|
||||
|
||||
CreateUser(user model.User) (db.Ref[model.User], error)
|
||||
ReadUser(id db.Ref[model.User]) (model.User, error)
|
||||
ReadUsers() ([]model.User, error)
|
||||
UpdateUser(user model.User) error
|
||||
DeleteUser(id db.Ref[model.User]) error
|
||||
|
||||
// Accounts
|
||||
|
||||
CreateAccount(account model.Account) (db.Ref[model.Account], error)
|
||||
ReadAccount(id db.Ref[model.Account]) (model.Account, error)
|
||||
UpdateAccount(user model.Account) error
|
||||
DeleteAccount(id db.Ref[model.Account]) error
|
||||
|
||||
// Users & Accounts
|
||||
|
||||
ReadUserAccounts(user db.Ref[model.User]) ([]model.Account, error)
|
||||
}
|
||||
|
||||
// Memory is an in-memory implementation of [Database] that can be used for testing
|
||||
type Memory struct {
|
||||
Database // TODO: Per ora almeno così facciamo compilare il codice
|
||||
|
||||
Users []model.User
|
||||
}
|
||||
|
||||
func (m *Memory) CreateUser(user model.User) (db.Ref[model.User], error) {
|
||||
m.Users = append(m.Users, user)
|
||||
return db.Ref[model.User](user.Id), nil
|
||||
}
|
||||
|
||||
func (m *Memory) ReadUser(id db.Ref[model.User]) (model.User, error) {
|
||||
for _, u := range m.Users {
|
||||
if u.Id == id {
|
||||
return u, nil
|
||||
}
|
||||
}
|
||||
|
||||
return model.User{}, fmt.Errorf(`no user with id "%s"`, id)
|
||||
}
|
||||
|
||||
func (m *Memory) ReadUsers() ([]model.User, error) {
|
||||
return m.Users, nil
|
||||
}
|
||||
|
||||
func (m *Memory) UpdateUser(user model.User) error {
|
||||
for i, u := range m.Users {
|
||||
if u.Id == user.Id {
|
||||
m.Users[i] = user
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf(`no user with id "%s"`, user.Id)
|
||||
}
|
||||
|
||||
func (m *Memory) DeleteUser(id db.Ref[model.User]) error {
|
||||
for i, u := range m.Users {
|
||||
if u.Id == id {
|
||||
m.Users = append(m.Users[:i], m.Users[i+1:]...)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf(`no user with id "%s"`, id)
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package tables
|
||||
|
||||
import (
|
||||
"git.phc.dm.unipi.it/phc/website/libs/db"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/website/server/model"
|
||||
)
|
||||
|
||||
var Users = db.AutoTable[model.User]("users")
|
||||
var Accounts = db.AutoTable[model.Account]("accounts")
|
@ -0,0 +1,28 @@
|
||||
package listautenti
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/website/libs/sl"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/website/server/database"
|
||||
)
|
||||
|
||||
func MountApiRoutesHook(l *sl.ServiceLocator, api fiber.Router) error {
|
||||
db, err := sl.Use(l, database.Slot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
api.Get("/lista-utenti", func(c *fiber.Ctx) error {
|
||||
users, err := db.ReadUsers()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: Pre-process data to strip server only fields...
|
||||
return c.JSON(users)
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
package listautenti_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
"github.com/valyala/fasthttp/fasthttputil"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/website/libs/db"
|
||||
"git.phc.dm.unipi.it/phc/website/libs/sl"
|
||||
"git.phc.dm.unipi.it/phc/website/libs/util"
|
||||
"git.phc.dm.unipi.it/phc/website/server"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/website/server/config"
|
||||
"git.phc.dm.unipi.it/phc/website/server/database"
|
||||
"git.phc.dm.unipi.it/phc/website/server/listautenti"
|
||||
"git.phc.dm.unipi.it/phc/website/server/model"
|
||||
)
|
||||
|
||||
func TestApiListaUtenti(t *testing.T) {
|
||||
|
||||
memDB := &database.Memory{
|
||||
Users: []model.User{
|
||||
{
|
||||
Id: "e39ad8d5-a087-4cb2-8fd7-5a6ca3f6a534",
|
||||
Username: "claire-doe",
|
||||
FullName: db.NewOption("Claire Doe"),
|
||||
Email: db.NewOption("claire.doe@example.org"),
|
||||
},
|
||||
{
|
||||
Id: "9b7109cd-95a1-41e9-a9f6-001a32c20ca1",
|
||||
Username: "john-smith",
|
||||
FullName: db.NewOption("John Smith"),
|
||||
Email: db.NewOption("john.smith@example.org"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
l := sl.New()
|
||||
|
||||
// Config
|
||||
sl.Provide(l, config.Slot, config.ExampleProductionConfig)
|
||||
|
||||
// Database
|
||||
sl.Provide[database.Database](l, database.Slot, memDB)
|
||||
|
||||
// Server
|
||||
sl.ProvideFunc(l, server.Slot, server.Configure)
|
||||
sl.ProvideHook(l, server.ApiRoutesHook,
|
||||
listautenti.MountApiRoutesHook,
|
||||
)
|
||||
|
||||
// Initialize server instance
|
||||
srv, err := sl.Use(l, server.Slot)
|
||||
assert.NilError(t, err)
|
||||
|
||||
//
|
||||
// Try doing the request
|
||||
//
|
||||
|
||||
req, err := http.NewRequest("GET", "http://localhost:4000/api/lista-utenti", nil)
|
||||
assert.NilError(t, err)
|
||||
|
||||
ln := fasthttputil.NewInmemoryListener()
|
||||
defer ln.Close()
|
||||
|
||||
go func() {
|
||||
err := fasthttp.Serve(ln, srv.Router.Handler())
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to serve: %v", err))
|
||||
}
|
||||
}()
|
||||
|
||||
client := http.Client{
|
||||
Transport: &http.Transport{
|
||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
return ln.Dial()
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
res, err := client.Do(req)
|
||||
assert.NilError(t, err)
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
assert.NilError(t, err)
|
||||
|
||||
assert.Equal(t, string(body), util.CompactIndentedLines(`
|
||||
[
|
||||
{
|
||||
"Id":"e39ad8d5-a087-4cb2-8fd7-5a6ca3f6a534",
|
||||
"Username":"claire-doe",
|
||||
"FullName":"Claire Doe",
|
||||
"Email":"claire.doe@example.org"
|
||||
},
|
||||
{
|
||||
"Id":"9b7109cd-95a1-41e9-a9f6-001a32c20ca1",
|
||||
"Username":"john-smith",
|
||||
"FullName":"John Smith",
|
||||
"Email":"john.smith@example.org"
|
||||
}
|
||||
]
|
||||
`))
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package model
|
||||
|
||||
import "git.phc.dm.unipi.it/phc/website/libs/db"
|
||||
|
||||
type User struct {
|
||||
// Id è l'id unico di questo utente, non è modificabile una volta creato
|
||||
// l'utente.
|
||||
Id db.Ref[User] `db:"id"`
|
||||
|
||||
// Username è il nome leggibile di questo utente utilizzato anche per le
|
||||
// route per singolo utente, deve essere unico nel sito.
|
||||
//
|
||||
// NOTE: Quando un utente accede per la prima volta di default gli viene
|
||||
// chiesto se usare quello dell'account che sta usando o se cambiarlo
|
||||
// (in teoria non dovrebbe essere un problema poterlo modificare
|
||||
// successivamente).
|
||||
Username string `db:"username"`
|
||||
|
||||
// FullName da mostrare in giro per il sito
|
||||
FullName db.Option[string] `db:"full_name"`
|
||||
|
||||
// Email per eventuale contatto
|
||||
Email db.Option[string] `db:"email"`
|
||||
}
|
||||
|
||||
type ProviderType string
|
||||
|
||||
const AteneoProvider ProviderType = "ateneo"
|
||||
const PoissonProvider ProviderType = "poisson"
|
||||
|
||||
type Account struct {
|
||||
Id db.Ref[Account] `db:"id"` // Id of this entity
|
||||
UserId db.Ref[User] `db:"user_id"` // UserId tells the owner of this account binding
|
||||
Provider ProviderType `db:"provider"` // Provider is the name of the authentication method
|
||||
|
||||
Token string `db:"token"` // Token to use to make requests on behalf of this user
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.phc.dm.unipi.it/phc/website/libs/sl"
|
||||
"git.phc.dm.unipi.it/phc/website/server/config"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type Server struct{ Router *fiber.App }
|
||||
|
||||
var Slot = sl.NewSlot[*Server]()
|
||||
|
||||
var ApiRoutesHook = sl.NewHook[fiber.Router]()
|
||||
|
||||
func Configure(l *sl.ServiceLocator) (*Server, error) {
|
||||
cfg, err := sl.Use(l, config.Slot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r := fiber.New(fiber.Config{})
|
||||
r.Static("/assets", "./out/frontend/assets")
|
||||
|
||||
api := r.Group("/api")
|
||||
if err := sl.UseHook(l, ApiRoutesHook, api); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go func() {
|
||||
log.Fatal(r.Listen(cfg.Host))
|
||||
}()
|
||||
|
||||
return &Server{r}, nil
|
||||
}
|
Before Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 1.8 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 1.5 MiB |
Before Width: | Height: | Size: 238 KiB |
Before Width: | Height: | Size: 200 KiB |
Before Width: | Height: | Size: 1.2 MiB |
Before Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.8 MiB |
Before Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 645 KiB |
Before Width: | Height: | Size: 1.8 MiB |
Before Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 262 KiB |
Before Width: | Height: | Size: 49 KiB |
Before Width: | Height: | Size: 342 KiB |
Before Width: | Height: | Size: 113 KiB |
Before Width: | Height: | Size: 608 KiB |
Before Width: | Height: | Size: 295 KiB |
@ -1,30 +0,0 @@
|
||||
/**
|
||||
* @typedef {{
|
||||
* image?: string,
|
||||
* course?: string,
|
||||
* title?: string,
|
||||
* author: string,
|
||||
* courseYear: string
|
||||
* }} AppuntiCardProps
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {AppuntiCardProps} param0
|
||||
* @returns
|
||||
*/
|
||||
export const AppuntiCard = ({ course, title, author, courseYear }) => {
|
||||
return (
|
||||
<div class="appunti-item">
|
||||
<div class="thumbnail"></div>
|
||||
{title && <div class="title">{title}</div>}
|
||||
{course && <div class="course">{course}</div>}
|
||||
<div class="author">@{author}</div>
|
||||
<div class="course-year">{courseYear}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const AppuntiList = ({ children }) => {
|
||||
return <div class="appunti-list">{children}</div>
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
import { type ComponentChildren } from 'preact'
|
||||
import { useState, useRef, useEffect } from 'preact/hooks'
|
||||
import { clsx, isMobile } from './lib/util'
|
||||
import { PhosphorIcon } from './Icon'
|
||||
|
||||
export const ComboBox = ({
|
||||
value,
|
||||
setValue,
|
||||
children,
|
||||
}: {
|
||||
value: string
|
||||
setValue: (s: string) => void
|
||||
children: Record<string, ComponentChildren>
|
||||
}) => {
|
||||
const [cloak, setCloak] = useState(true)
|
||||
const [open, setOpen] = useState(true)
|
||||
const comboRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
const handleClick = (e: MouseEvent) => {
|
||||
if (comboRef.current && !comboRef.current.contains(e.target as Node)) {
|
||||
setOpen(false)
|
||||
}
|
||||
}
|
||||
document.addEventListener('mousedown', handleClick)
|
||||
return () => document.removeEventListener('mousedown', handleClick)
|
||||
}, [])
|
||||
|
||||
const [itemWidth, setItemWidth] = useState<number>(200)
|
||||
|
||||
useEffect(() => {
|
||||
setOpen(false)
|
||||
setCloak(false)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div class="combobox" ref={comboRef} style={{ width: isMobile() ? undefined : itemWidth + 48 + 'px' }}>
|
||||
<div class="selected" onClick={() => setOpen(!open)}>
|
||||
<div class="content">{children[value]}</div>
|
||||
{/* <span class="material-symbols-outlined">expand_more</span> */}
|
||||
<PhosphorIcon name="caret-down" />
|
||||
</div>
|
||||
{open && (
|
||||
<div class={clsx('dropdown', cloak && 'invisible')} ref={el => el && setItemWidth(el.offsetWidth)}>
|
||||
{Object.keys(children).map(key => (
|
||||
<div
|
||||
class="option"
|
||||
onClick={() => {
|
||||
setValue(key)
|
||||
setOpen(false)
|
||||
}}
|
||||
>
|
||||
{children[key]}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
import { useState } from 'preact/hooks'
|
||||
|
||||
export const Counter = ({}) => {
|
||||
const [count, setCount] = useState(0)
|
||||
|
||||
return (
|
||||
<div class="counter">
|
||||
<button onClick={() => setCount(value => value - 1)}>-</button>
|
||||
<div class="value">{count}</div>
|
||||
<button onClick={() => setCount(value => value + 1)}>+</button>
|
||||
</div>
|
||||
)
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
import { useEffect, useState } from 'preact/hooks'
|
||||
import { Funnel } from '@phosphor-icons/react'
|
||||
import { marked } from 'marked'
|
||||
|
||||
import extendedLatex from '@/client/lib/marked-latex'
|
||||
|
||||
marked.use(
|
||||
extendedLatex({
|
||||
lazy: false,
|
||||
render: (formula: string, display: boolean) => {
|
||||
return display ? '$$' + formula + '$$' : '$' + formula + '$'
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
import type { Database } from '@/data/domande-esami.yaml'
|
||||
|
||||
const useRemoteValue = <T,>(url: string): T | null => {
|
||||
const [value, setValue] = useState<T | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(value => setValue(value))
|
||||
.catch(error => console.error(error))
|
||||
}, [url])
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
type Props = {
|
||||
course: string
|
||||
}
|
||||
|
||||
export const DomandeEsamiCourse = ({ course }: Props) => {
|
||||
const database = useRemoteValue<Database>(`/domande-esami/api/${course}.json`)
|
||||
if (!database) {
|
||||
return <>Loading...</>
|
||||
}
|
||||
|
||||
if ('requestIdleCallback' in window) {
|
||||
// @ts-ignore
|
||||
requestIdleCallback(() => window.renderMath())
|
||||
} else {
|
||||
// @ts-ignore
|
||||
setTimeout(() => window.renderMath(), 100)
|
||||
}
|
||||
|
||||
const courseTags = [
|
||||
...new Set(
|
||||
database.questions.filter(question => question.course === course).flatMap(question => question.tags),
|
||||
),
|
||||
]
|
||||
|
||||
const [selectedTag, setSelectedTag] = useState<string | null>(null)
|
||||
|
||||
const filteredQuestions = database.questions
|
||||
.filter(question => question.course === course)
|
||||
.filter(question => (selectedTag ? question.tags.includes(selectedTag) : true))
|
||||
|
||||
return (
|
||||
<>
|
||||
<div class="grid-center text-center">
|
||||
<h3>
|
||||
<a href="/domande-esami">Domande Orali</a>
|
||||
</h3>
|
||||
<h1>{database.names[course]}</h1>
|
||||
</div>
|
||||
|
||||
{courseTags.length > 1 && (
|
||||
<div class="card filter">
|
||||
<div class="grid-h">
|
||||
<Funnel />
|
||||
<strong>Filtra Tag</strong>
|
||||
</div>
|
||||
<div class="flex-row-wrap">
|
||||
{!selectedTag
|
||||
? courseTags.map(tag => (
|
||||
<div class="chip clickable" onClick={() => setSelectedTag(tag)}>
|
||||
{tag}
|
||||
</div>
|
||||
))
|
||||
: courseTags.map(tag => (
|
||||
<div
|
||||
class={tag === selectedTag ? 'chip clickable' : 'chip clickable disabled'}
|
||||
onClick={() => setSelectedTag(tag === selectedTag ? null : tag)}
|
||||
>
|
||||
{tag}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div class="wide-card-list" id="questions">
|
||||
{filteredQuestions.length === 0 ? (
|
||||
<div class="grid-center">
|
||||
<em>No questions found</em>
|
||||
</div>
|
||||
) : (
|
||||
filteredQuestions.map(question => (
|
||||
<div class="card">
|
||||
<div
|
||||
class="text"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: marked(question.content, { async: false }),
|
||||
}}
|
||||
/>
|
||||
<div class="metadata">
|
||||
{question.tags.map(tag => (
|
||||
<div class="chip small">{tag}</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
const icons = Object.fromEntries(
|
||||
Object.entries(
|
||||
import.meta.glob<{ default: ImageMetadata }>(`node_modules/@phosphor-icons/core/assets/light/*.svg`, {
|
||||
eager: true,
|
||||
}),
|
||||
).map(([path, module]) => [path.split('/').pop()!.split('.')[0].replace('-light', ''), module]),
|
||||
)
|
||||
|
||||
type Props = {
|
||||
name: string
|
||||
}
|
||||
|
||||
export const PhosphorIcon = ({ name }: Props) => {
|
||||
const icon = icons[name]
|
||||
|
||||
if (!icon) {
|
||||
throw new Error(`Icon "${name}" not found`)
|
||||
}
|
||||
|
||||
return <img class="phosphor-icon" src={icon.default.src} alt={name} />
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
import { useComputed, useSignal, type ReadonlySignal } from '@preact/signals'
|
||||
import type { JSX } from 'preact/jsx-runtime'
|
||||
|
||||
export const ShowMore = <T extends any>({
|
||||
items,
|
||||
pageSize,
|
||||
children,
|
||||
}: {
|
||||
items: ReadonlySignal<T[]>
|
||||
pageSize: number
|
||||
children: (item: T) => JSX.Element
|
||||
}) => {
|
||||
const $shownItems = useSignal(pageSize)
|
||||
|
||||
const $paginatedItems = useComputed(() => {
|
||||
return items.value.slice(0, $shownItems.value)
|
||||
})
|
||||
|
||||
return (
|
||||
<>
|
||||
{$paginatedItems.value.map(children)}
|
||||
<div class="show-more">
|
||||
{$shownItems.value < items.value.length && (
|
||||
<button onClick={() => ($shownItems.value += pageSize)}>Mostra altri</button>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
@ -1,166 +0,0 @@
|
||||
import { useComputed, useSignal } from '@preact/signals'
|
||||
import Fuse from 'fuse.js'
|
||||
import { useEffect } from 'preact/hooks'
|
||||
import { ShowMore } from './Paginate'
|
||||
import { ComboBox } from './ComboBox'
|
||||
import { PhosphorIcon } from './Icon'
|
||||
|
||||
type User = {
|
||||
uid: string
|
||||
gecos: string
|
||||
}
|
||||
|
||||
const FILTERS = {
|
||||
utenti: {
|
||||
icon: 'user',
|
||||
label: 'Utenti',
|
||||
},
|
||||
macchinisti: {
|
||||
icon: 'wrench',
|
||||
label: 'Macchinisti',
|
||||
},
|
||||
rappstud: {
|
||||
icon: 'bank',
|
||||
label: 'Rappresentanti',
|
||||
},
|
||||
}
|
||||
|
||||
function applyPatches(users: User[]) {
|
||||
users.forEach(user => {
|
||||
// strip ",+" from the end of the gecos field
|
||||
user.gecos = user.gecos.replace(/,+$/, '')
|
||||
|
||||
// capitalize the first letter of each word
|
||||
user.gecos = user.gecos.replace(/\b\w/g, c => c.toUpperCase())
|
||||
})
|
||||
|
||||
// reverse the order of the users
|
||||
users.reverse()
|
||||
}
|
||||
|
||||
const MACCHINISTI = ['delucreziis', 'minnocci', 'baldino', 'manicastri', 'llombardo', 'serdyuk']
|
||||
|
||||
const RAPPSTUD = [
|
||||
'smannella',
|
||||
'lotti',
|
||||
'rotolo',
|
||||
'saccani',
|
||||
'carbone',
|
||||
'mburatti',
|
||||
'ppuddu',
|
||||
'marinari',
|
||||
'evsilvestri',
|
||||
'tateo',
|
||||
'graccione',
|
||||
'dilella',
|
||||
'rocca',
|
||||
'odetti',
|
||||
'borso',
|
||||
'numero',
|
||||
]
|
||||
|
||||
export const UtentiPage = () => {
|
||||
const $utentiData = useSignal<User[]>([])
|
||||
|
||||
const $filter = useSignal('utenti')
|
||||
|
||||
const $filteredData = useComputed(() =>
|
||||
$filter.value === 'macchinisti'
|
||||
? $utentiData.value.filter(user => MACCHINISTI.includes(user.uid))
|
||||
: $filter.value === 'rappstud'
|
||||
? $utentiData.value.filter(user => RAPPSTUD.includes(user.uid))
|
||||
: $utentiData.value,
|
||||
)
|
||||
|
||||
const $fuse = useComputed(
|
||||
() =>
|
||||
new Fuse($filteredData.value, {
|
||||
keys: ['gecos', 'uid'],
|
||||
}),
|
||||
)
|
||||
|
||||
const $searchText = useSignal('')
|
||||
const $searchResults = useComputed(() =>
|
||||
$searchText.value.trim().length > 0
|
||||
? ($fuse.value?.search($searchText.value).map(result => result.item) ?? [])
|
||||
: $filteredData.value,
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
fetch('https://poisson.phc.dm.unipi.it/users.json')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
applyPatches(data)
|
||||
|
||||
$utentiData.value = data
|
||||
|
||||
$fuse.value.setCollection(data)
|
||||
})
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<>
|
||||
<div class="search-bar">
|
||||
<ComboBox value={$filter.value} setValue={s => ($filter.value = s)}>
|
||||
{Object.fromEntries(
|
||||
Object.entries(FILTERS).map(([k, v]) => [
|
||||
k,
|
||||
<>
|
||||
{/* <span class="material-symbols-outlined">{v.icon}</span> {v.label} */}
|
||||
<PhosphorIcon name={v.icon} />
|
||||
{v.label}
|
||||
</>,
|
||||
]),
|
||||
)}
|
||||
</ComboBox>
|
||||
<div class="search">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Cerca un utente Poisson..."
|
||||
onInput={e => ($searchText.value = e.currentTarget.value)}
|
||||
value={$searchText.value}
|
||||
/>
|
||||
{/* <span class="material-symbols-outlined">search</span> */}
|
||||
<PhosphorIcon name="magnifying-glass" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="search-results">
|
||||
{$searchResults.value ? (
|
||||
<ShowMore items={$searchResults} pageSize={100}>
|
||||
{poissonUser => (
|
||||
<div class="search-result">
|
||||
<div class="icon">
|
||||
{/* <span class="material-symbols-outlined">
|
||||
{RAPPSTUD.includes(poissonUser.uid)
|
||||
? 'account_balance'
|
||||
: MACCHINISTI.includes(poissonUser.uid)
|
||||
? 'construction'
|
||||
: 'person'}
|
||||
</span> */}
|
||||
<PhosphorIcon
|
||||
name={
|
||||
RAPPSTUD.includes(poissonUser.uid)
|
||||
? 'bank'
|
||||
: MACCHINISTI.includes(poissonUser.uid)
|
||||
? 'wrench'
|
||||
: 'user'
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div class="text">{poissonUser.gecos}</div>
|
||||
<div class="right">
|
||||
<a href={`https://poisson.phc.dm.unipi.it/~${poissonUser.uid}`} target="_blank">
|
||||
{/* <span class="material-symbols-outlined">open_in_new</span> */}
|
||||
<PhosphorIcon name="arrow-square-out" />
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</ShowMore>
|
||||
) : (
|
||||
<>Nessun risultato</>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
const $debugConsole = document.createElement('div')
|
||||
|
||||
$debugConsole.style.position = 'fixed'
|
||||
$debugConsole.style.bottom = '0'
|
||||
$debugConsole.style.left = '0'
|
||||
$debugConsole.style.width = '100%'
|
||||
$debugConsole.style.height = '25vh'
|
||||
$debugConsole.style.backgroundColor = 'black'
|
||||
$debugConsole.style.color = 'white'
|
||||
$debugConsole.style.overflow = 'auto'
|
||||
$debugConsole.style.padding = '10px'
|
||||
$debugConsole.style.boxSizing = 'border-box'
|
||||
$debugConsole.style.fontFamily = 'monospace'
|
||||
$debugConsole.style.zIndex = '9999'
|
||||
$debugConsole.style.fontSize = '15px'
|
||||
$debugConsole.style.opacity = '0.8'
|
||||
|
||||
document.body.appendChild($debugConsole)
|
||||
|
||||
function logDebugConsole(...args) {
|
||||
$debugConsole.innerHTML += args.join(' ') + '<br>'
|
||||
}
|
||||
|
||||
console.error = logDebugConsole
|
||||
console.warn = logDebugConsole
|
||||
console.log = logDebugConsole
|
||||
console.debug = logDebugConsole
|
@ -1,83 +0,0 @@
|
||||
// took from: https://github.com/sxyazi/marked-extended-latex
|
||||
// this has a peer dependency bug
|
||||
|
||||
const CLASS_NAME = 'latex-b172fea480b'
|
||||
|
||||
const extBlock = options => ({
|
||||
name: 'latex-block',
|
||||
level: 'block',
|
||||
start(src) {
|
||||
return src.match(/\$\$[^\$]/)?.index ?? -1
|
||||
},
|
||||
tokenizer(src, tokens) {
|
||||
const match = /^\$\$([^\$]+)\$\$/.exec(src)
|
||||
return match ? { type: 'latex-block', raw: match[0], formula: match[1] } : undefined
|
||||
},
|
||||
renderer(token) {
|
||||
if (!options.lazy) return options.render(token.formula, true)
|
||||
return `<span class="${CLASS_NAME}" block>${token.formula}</span>`
|
||||
},
|
||||
})
|
||||
|
||||
const extInline = options => ({
|
||||
name: 'latex',
|
||||
level: 'inline',
|
||||
start(src) {
|
||||
return src.match(/\$[^\$]/)?.index ?? -1
|
||||
},
|
||||
tokenizer(src, tokens) {
|
||||
const match = /^\$([^\$]+)\$/.exec(src)
|
||||
return match ? { type: 'latex', raw: match[0], formula: match[1] } : undefined
|
||||
},
|
||||
renderer(token) {
|
||||
if (!options.lazy) return options.render(token.formula, false)
|
||||
return `<span class="${CLASS_NAME}">${token.formula}</span>`
|
||||
},
|
||||
})
|
||||
|
||||
let observer
|
||||
/* istanbul ignore next */
|
||||
export default (options = {}) => {
|
||||
/* istanbul ignore next */
|
||||
if (options.lazy && options.env !== 'test') {
|
||||
observer = new IntersectionObserver(
|
||||
(entries, self) => {
|
||||
for (const entry of entries) {
|
||||
if (!entry.isIntersecting) {
|
||||
continue
|
||||
}
|
||||
|
||||
const span = entry.target
|
||||
self.unobserve(span)
|
||||
|
||||
Promise.resolve(options.render(span.innerText, span.hasAttribute('block'))).then(html => {
|
||||
span.innerHTML = html
|
||||
})
|
||||
span.classList.add('latex-rendered')
|
||||
}
|
||||
},
|
||||
{ threshold: 1.0 },
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
extensions: [extBlock(options), extInline(options)],
|
||||
}
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
export const observe = () => {
|
||||
if (!observer) {
|
||||
return
|
||||
}
|
||||
|
||||
observer.disconnect()
|
||||
document.querySelectorAll(`span.${CLASS_NAME}:not(.latex-rendered)`).forEach(span => {
|
||||
observer.observe(span)
|
||||
})
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
export const disconnect = () => {
|
||||
observer?.disconnect()
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
import { useEffect, useState } from 'preact/hooks'
|
||||
|
||||
export const trottleDebounce = <T extends any[], R>(
|
||||
fn: (...args: T) => R,
|
||||
delay: number,
|
||||
options: { leading?: boolean; trailing?: boolean } = {},
|
||||
): ((...args: T) => R | undefined) => {
|
||||
let lastCall = 0
|
||||
let lastResult: R | undefined
|
||||
let lastArgs: T | undefined
|
||||
let timeout: NodeJS.Timeout | undefined
|
||||
|
||||
const leading = options.leading ?? true
|
||||
const trailing = options.trailing ?? true
|
||||
|
||||
return (...args: T): R | undefined => {
|
||||
lastArgs = args
|
||||
if (leading && Date.now() - lastCall >= delay) {
|
||||
lastCall = Date.now()
|
||||
lastResult = fn(...args)
|
||||
} else {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout)
|
||||
}
|
||||
timeout = setTimeout(() => {
|
||||
if (trailing && lastArgs) {
|
||||
lastCall = Date.now()
|
||||
lastResult = fn(...lastArgs)
|
||||
}
|
||||
}, delay)
|
||||
}
|
||||
return lastResult
|
||||
}
|
||||
}
|
||||
|
||||
export type ClassValue = string | ClassValue[] | Record<string, boolean> | false | undefined
|
||||
|
||||
export function clsx(...args: ClassValue[]): string {
|
||||
return args
|
||||
.flatMap(arg => {
|
||||
if (typeof arg === 'string') {
|
||||
return arg
|
||||
} else if (Array.isArray(arg)) {
|
||||
return clsx(...arg)
|
||||
} else if (typeof arg === 'boolean') {
|
||||
return []
|
||||
} else if (typeof arg === 'object') {
|
||||
return Object.entries(arg).flatMap(([key, value]) => (value ? key : []))
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
})
|
||||
.join(' ')
|
||||
}
|
||||
|
||||
export const isMobile = () => {
|
||||
const [windowWidth, setWindowWidth] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
setWindowWidth(window.innerWidth)
|
||||
|
||||
const handleResize = () => setWindowWidth(window.innerWidth)
|
||||
window.addEventListener('resize', handleResize)
|
||||
|
||||
return () => window.removeEventListener('resize', handleResize)
|
||||
}, [])
|
||||
|
||||
return windowWidth < 1024
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
---
|
||||
import PhosphorIcon from './PhosphorIcon.astro'
|
||||
|
||||
const ICONS_MAP: Record<string, string> = {
|
||||
github: 'github-logo',
|
||||
linkedin: 'linkedin-logo',
|
||||
website: 'globe',
|
||||
mail: 'mailbox',
|
||||
}
|
||||
|
||||
type Props = {
|
||||
fullName: string
|
||||
description: string
|
||||
|
||||
image: ImageMetadata
|
||||
|
||||
entranceDate: number
|
||||
exitDate?: number
|
||||
|
||||
founder?: boolean
|
||||
|
||||
social?: {
|
||||
github?: string
|
||||
linkedin?: string
|
||||
website?: string
|
||||
mail?: string
|
||||
}
|
||||
}
|
||||
|
||||
const { fullName, description, image, entranceDate, exitDate, founder, social } = Astro.props
|
||||
---
|
||||
|
||||
<div class="bubble">
|
||||
<img src={image.src} alt={fullName.toLowerCase()} />
|
||||
<div class="title">{fullName}</div>
|
||||
<div class="date">{entranceDate}—{exitDate ?? 'Presente'}</div>
|
||||
{founder && <div class="founder">Fondatore</div>}
|
||||
<div class="description">{description}</div>
|
||||
{
|
||||
social && (
|
||||
<div class="social">
|
||||
{Object.entries(social).map(([key, value]) => (
|
||||
<a href={value} target="_blank" rel="noopener noreferrer">
|
||||
<PhosphorIcon name={ICONS_MAP[key] ?? 'question-mark'} />
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</div>
|
@ -1,12 +0,0 @@
|
||||
---
|
||||
type Props = {
|
||||
large?: boolean
|
||||
style?: string
|
||||
}
|
||||
|
||||
const { large, ...props } = Astro.props
|
||||
---
|
||||
|
||||
<div class:list={['card', large && 'large']} {...props}>
|
||||
<slot />
|
||||
</div>
|
@ -1,9 +0,0 @@
|
||||
<footer>
|
||||
<div class="text">
|
||||
<p>
|
||||
© PHC 2024 • <a href="mailto:macchinisti@lists.dm.unipi.it"
|
||||
>macchinisti@lists.dm.unipi.it</a
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
@ -1,56 +0,0 @@
|
||||
---
|
||||
const links = [
|
||||
{ href: '/utenti', text: 'Utenti' },
|
||||
// { href: '/macchinisti', text: 'Macchinisti' },
|
||||
// { href: '/appunti', text: 'Appunti' },
|
||||
{ href: '/notizie', text: 'Notizie' },
|
||||
{ href: '/guide', text: 'Guide' },
|
||||
{ href: '/domande-esami', text: 'Domande Orali' },
|
||||
{ href: '/storia', text: 'Storia' },
|
||||
// { href: '/login', text: 'Login' },
|
||||
]
|
||||
---
|
||||
|
||||
<header>
|
||||
<!-- main logo on the left -->
|
||||
<a href="/" class="logo">
|
||||
<img src="/images/phc-logo-2024-11@x8.png" alt="phc logo" />
|
||||
</a>
|
||||
|
||||
<!-- hidden checkbox for mobile js-less sidebar interaction -->
|
||||
<input type="checkbox" id="header-menu-toggle" />
|
||||
|
||||
<!-- desktop navbar links -->
|
||||
<div class="links desktop-only">
|
||||
{
|
||||
links.map(link => (
|
||||
<a role="button" href={link.href}>
|
||||
{link.text}
|
||||
</a>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- sidebar menu for mobile -->
|
||||
<div class="mobile-only">
|
||||
<label id="header-menu-toggle-menu" role="button" class="flat icon" for="header-menu-toggle">
|
||||
<span class="material-symbols-outlined">menu</span>
|
||||
</label>
|
||||
<label id="header-menu-toggle-close" role="button" class="flat icon" for="header-menu-toggle">
|
||||
<span class="material-symbols-outlined">close</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- sidebar menu only visible on mobile when #header-menu-toggle is checked -->
|
||||
<div class="side-menu">
|
||||
<div class="links">
|
||||
{
|
||||
links.map(link => (
|
||||
<a role="button" href={link.href}>
|
||||
{link.text}
|
||||
</a>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
@ -1,26 +0,0 @@
|
||||
---
|
||||
type Props = {
|
||||
color: string
|
||||
}
|
||||
|
||||
const { color } = Astro.props
|
||||
|
||||
const patternId = 'zig-zag-' + color.slice(1)
|
||||
---
|
||||
|
||||
<div class="zig-zag">
|
||||
<svg
|
||||
width="100%"
|
||||
height="2rem"
|
||||
viewBox="0 0 1 1"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
preserveAspectRatio="xMinYMid meet"
|
||||
>
|
||||
<defs>
|
||||
<pattern id={patternId} x="0" y="0" width="2" height="1" patternUnits="userSpaceOnUse">
|
||||
<path fill={color} d="M 0,1 L 1,0 L 2,1 L 0,1"></path>
|
||||
</pattern>
|
||||
</defs>
|
||||
<rect fill={`url(#${patternId})`} x="0" y="0" width="1000" height="1"></rect>
|
||||
</svg>
|
||||
</div>
|
@ -1,21 +0,0 @@
|
||||
---
|
||||
import { Image } from 'astro:assets'
|
||||
|
||||
type Props = {
|
||||
name: string
|
||||
}
|
||||
|
||||
const { name } = Astro.props
|
||||
|
||||
const icons = Object.fromEntries(
|
||||
Object.entries(
|
||||
import.meta.glob<{ default: ImageMetadata }>(`node_modules/@phosphor-icons/core/assets/light/*.svg`),
|
||||
).map(([path, module]) => [path.split('/').pop()!.split('.')[0].replace('-light', ''), module]),
|
||||
)
|
||||
|
||||
if (!icons[name]) {
|
||||
throw new Error(`Icon "${name}" not found`)
|
||||
}
|
||||
---
|
||||
|
||||
<Image class="phosphor-icon" src={icons[name]()} alt={name} />
|
@ -1,24 +0,0 @@
|
||||
---
|
||||
// Card.astro
|
||||
export interface Props {
|
||||
title: string
|
||||
href: string
|
||||
|
||||
imgSrc?: string
|
||||
style?: string
|
||||
}
|
||||
|
||||
const { href, imgSrc, style, title } = Astro.props
|
||||
---
|
||||
|
||||
<a target="_blank" href={href} style={style}>
|
||||
<div class="project">
|
||||
<div class="image">
|
||||
{imgSrc ? <img src={imgSrc} alt={'logo for ' + title.toLowerCase()} /> : <div class="box" />}
|
||||
</div>
|
||||
<div class="title">{title}</div>
|
||||
<div class="description">
|
||||
<slot />
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
@ -1,14 +0,0 @@
|
||||
---
|
||||
const { year, title } = Astro.props
|
||||
---
|
||||
|
||||
<div class="timeline-item">
|
||||
<div class="content">
|
||||
<div class="card">
|
||||
<div class="title">{year} • {title}</div>
|
||||
<div class="text">
|
||||
<slot />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -1,14 +0,0 @@
|
||||
---
|
||||
import { JSDOM } from 'jsdom'
|
||||
import Container from './Container.astro'
|
||||
|
||||
const language = Astro.props['data-language'] ?? 'text'
|
||||
|
||||
const html = await Astro.slots.render('default')
|
||||
|
||||
const rawCode = new JSDOM(html).window.document.body.textContent
|
||||
---
|
||||
|
||||
<pre {...Astro.props}><slot /></pre>
|
||||
|
||||
{language === 'astro' && <Container set:html={rawCode} />}
|
@ -1,9 +0,0 @@
|
||||
---
|
||||
const { size, ...rest } = Astro.props
|
||||
---
|
||||
|
||||
<div class:list={['container', size ?? 'normal']} {...rest}>
|
||||
<div class="content">
|
||||
<slot />
|
||||
</div>
|
||||
</div>
|
@ -1,20 +0,0 @@
|
||||
---
|
||||
type Props = {
|
||||
colors: string[]
|
||||
}
|
||||
|
||||
const { colors } = Astro.props
|
||||
---
|
||||
|
||||
<div class="palette">
|
||||
{
|
||||
colors.map(value => (
|
||||
<>
|
||||
<div class="color">
|
||||
<div class="region" style={{ backgroundColor: value }} />
|
||||
</div>
|
||||
<div class="label">{value}</div>
|
||||
</>
|
||||
))
|
||||
}
|
||||
</div>
|
@ -1,58 +0,0 @@
|
||||
import { z, defineCollection } from 'astro:content'
|
||||
|
||||
// Una notizia ha una data di pubblicazione ma non ha un autore in quanto sono
|
||||
// notizie generiche sul PHC e non sono scritte da un autore specifico
|
||||
const newsCollection = defineCollection({
|
||||
type: 'content',
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
description: z.string(),
|
||||
publishDate: z.date(),
|
||||
image: z
|
||||
.object({
|
||||
url: z.string(),
|
||||
alt: z.string(),
|
||||
})
|
||||
.optional(),
|
||||
}),
|
||||
})
|
||||
|
||||
// Una guida ha un autore ma non ha una data di pubblicazione in quanto è un
|
||||
// contenuto statico e non è importante sapere quando è stata pubblicata
|
||||
const guidesCollection = defineCollection({
|
||||
type: 'content',
|
||||
schema: z.object({
|
||||
id: z.string(),
|
||||
title: z.string(),
|
||||
description: z.string(),
|
||||
author: z.string(),
|
||||
series: z.string().optional(),
|
||||
tags: z.array(z.string()),
|
||||
}),
|
||||
})
|
||||
|
||||
// Per ora sono su un sito a parte ma prima o poi verranno migrati qui
|
||||
const seminariettiCollection = defineCollection({
|
||||
type: 'content',
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
description: z.string(),
|
||||
author: z.string(),
|
||||
publishDate: z.date(),
|
||||
eventDate: z.date(),
|
||||
tags: z.array(z.string()),
|
||||
}),
|
||||
})
|
||||
|
||||
const metaCollection = defineCollection({
|
||||
type: 'content',
|
||||
schema: z.any(),
|
||||
})
|
||||
|
||||
// Export a single `collections` object to register your collection(s)
|
||||
export const collections = {
|
||||
news: newsCollection,
|
||||
guides: guidesCollection,
|
||||
seminarietti: seminariettiCollection,
|
||||
meta: metaCollection,
|
||||
}
|
@ -1,353 +0,0 @@
|
||||
---
|
||||
id: git-101
|
||||
title: Git 101
|
||||
description: Una guida 📚 introduttiva alle basi di Git
|
||||
author: Luca Lombardo
|
||||
tags: [git, gitea]
|
||||
---
|
||||
|
||||
Git è un sistema di controllo di versione distribuito creato per gestire progetti di qualsiasi dimensione, mantenendo traccia delle modifiche al codice sorgente. Questa guida ci accompagnerà dai concetti di base fino alle funzionalità avanzate.
|
||||
|
||||
---
|
||||
|
||||
## **1. Introduzione a Git**
|
||||
|
||||
### **Cos'è Git?**
|
||||
|
||||
- **Sistema di controllo di versione**: Gestisce le modifiche al codice sorgente nel tempo.
|
||||
|
||||
- **Distribuito**: Ogni sviluppatore ha una copia del repository.
|
||||
|
||||
- **Veloce e leggero**: Ottimizzato per la velocità e le prestazioni.
|
||||
|
||||
### **Perché usare Git?**
|
||||
|
||||
- **Tracciabilità**: Ogni modifica è tracciata e reversibile.
|
||||
|
||||
- **Collaborazione**: Più persone possono lavorare sullo stesso progetto.
|
||||
|
||||
- **Backup**: Repository remoto per il backup del codice.
|
||||
|
||||
- **Branching**: Lavoriamo su nuove funzionalità senza influenzare il codice principale.
|
||||
|
||||
---
|
||||
|
||||
## **2. Installazione**
|
||||
|
||||
> Se ci troviamo al dipartimento di matematica a Pisa, è già installato su tutte le macchine dell'aula 3 ed aula 4!
|
||||
|
||||
### **Windows**
|
||||
|
||||
1. Scarichiamo [Git for Windows](https://git-scm.com/download/win).
|
||||
|
||||
2. Seguiamo il wizard di installazione.
|
||||
|
||||
3. Durante l'installazione:
|
||||
|
||||
- Selezioniamo "Git Bash" come terminale.
|
||||
|
||||
- Configuriamo un editor di testo (es. Vim o Nano).
|
||||
|
||||
### **macOS**
|
||||
|
||||
1. Usiamo `brew` per installare Git:
|
||||
|
||||
```bash
|
||||
brew install git
|
||||
```
|
||||
|
||||
### **Linux**
|
||||
|
||||
1. Installiamo Git usando il nostro gestore di pacchetti:
|
||||
|
||||
- **Debian/Ubuntu**:
|
||||
|
||||
```bash
|
||||
sudo apt update
|
||||
sudo apt install git
|
||||
```
|
||||
|
||||
- **Arch Linux**:
|
||||
|
||||
```bash
|
||||
sudo pacman -S git
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## **3. Configurazione iniziale**
|
||||
|
||||
Una volta installato, configuriamo Git con il nostro nome e indirizzo email:
|
||||
|
||||
```bash
|
||||
git config --global user.name "Il Nostro Nome"
|
||||
git config --global user.email "nostro@email.com"
|
||||
```
|
||||
|
||||
### **Verifica configurazione**
|
||||
|
||||
```bash
|
||||
git config --list
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## **4. Concetti fondamentali**
|
||||
|
||||
### **Repository**
|
||||
|
||||
- **Repository locale**: Una cartella sul nostro computer che contiene il nostro progetto.
|
||||
|
||||
- **Repository remoto**: Una versione del progetto ospitata su un server (es. GitHub, GitLab).
|
||||
|
||||
### **Branch**
|
||||
|
||||
Un ramo permette di lavorare su modifiche isolate rispetto al codice principale (branch `main` o `master`).
|
||||
|
||||
### **Commit**
|
||||
|
||||
Una snapshot del nostro codice in un determinato momento.
|
||||
|
||||
---
|
||||
|
||||
## **5. Creazione e gestione di un repository**
|
||||
|
||||
### **Inizializzare un nuovo repository**
|
||||
|
||||
Se stiamo iniziando un nuovo progetto, possiamo creare un nuovo repository con il comando:
|
||||
|
||||
```bash
|
||||
git init
|
||||
```
|
||||
|
||||
### **Clonare un repository esistente**
|
||||
|
||||
Se invece vogliamo lavorare su un progetto esistente, possiamo clonare da remoto con:
|
||||
|
||||
```bash
|
||||
git clone <URL>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## **6. Lavorare con Git**
|
||||
|
||||
### **Aggiungere file**
|
||||
|
||||
Aggiungiamo file allo stage per includerli nel prossimo commit:
|
||||
|
||||
```bash
|
||||
git add <nome-file>
|
||||
# Oppure, per aggiungere tutti i file:
|
||||
git add .
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### **Commit**
|
||||
|
||||
Il comando **`git commit`** è utilizzato per registrare le modifiche nel repository locale. Ogni commit è una snapshot del progetto, contenente tutte le modifiche che sono state aggiunte tramite `git add`.
|
||||
|
||||
#### Come funziona:
|
||||
|
||||
1. **Aggiungiamo modifiche all'area di staging**:
|
||||
Prima di fare un commit, dobbiamo aggiungere i file che vogliamo includere al prossimo commit usando `git add`. Questo comando prepara i file per essere salvati nella cronologia del repository.
|
||||
|
||||
Esempio:
|
||||
|
||||
```bash
|
||||
git add <nome-file>
|
||||
# Oppure per aggiungere tutti i file modificati
|
||||
git add .
|
||||
```
|
||||
|
||||
2. **Effettuiamo il commit**:
|
||||
Una volta che i file sono nell'area di staging, possiamo fare un commit. Ogni commit dovrebbe avere un messaggio descrittivo che spieghi cosa è stato cambiato nel progetto.
|
||||
|
||||
Comando per fare un commit:
|
||||
|
||||
```bash
|
||||
git commit -m "Descrizione chiara del cambiamento"
|
||||
```
|
||||
|
||||
L'opzione `-m` permette di aggiungere il messaggio direttamente dalla linea di comando. Se omettiamo `-m`, Git aprirà un editor di testo per scrivere il messaggio di commit.
|
||||
|
||||
#### Cosa succede dietro le quinte:
|
||||
|
||||
- Git salva lo stato dei file nell'area di staging in un commit, che viene aggiunto alla cronologia del repository locale.
|
||||
|
||||
- Ogni commit ha un identificatore unico (hash) che consente di risalire facilmente alle modifiche in qualsiasi momento.
|
||||
|
||||
---
|
||||
|
||||
### **Push**
|
||||
|
||||
**`git push`** è il comando che ci permette di inviare le modifiche dal nostro repository locale a un repository remoto (ad esempio su GitHub, GitLab, Bitbucket, ecc.).
|
||||
|
||||
#### Come funziona:
|
||||
|
||||
1. Dopo aver fatto uno o più commit locali, dobbiamo inviare queste modifiche al repository remoto.
|
||||
|
||||
2. Per fare questo, usiamo il comando **`git push`** seguito dal nome del remoto (di solito `origin` per il repository remoto di default) e dal nome del branch (di solito `main` o `master`, ma potrebbe essere qualsiasi altro nome di branch che stiamo utilizzando).
|
||||
|
||||
Comando per inviare le modifiche:
|
||||
|
||||
```bash
|
||||
git push origin main
|
||||
```
|
||||
|
||||
#### Cosa succede dietro le quinte:
|
||||
|
||||
- Git confronta il nostro branch locale con il branch remoto. Se ci sono nuovi commit nel branch remoto che non sono ancora nel nostro branch locale, ci verrà richiesto di fare un **pull** per aggiornare prima di fare il push.
|
||||
|
||||
- Il nostro repository locale viene sincronizzato con il remoto, rendendo le modifiche visibili a tutti gli altri che hanno accesso al repository remoto.
|
||||
|
||||
#### Errori comuni:
|
||||
|
||||
- Se il repository remoto è stato aggiornato nel frattempo da qualcun altro (ad esempio, con un altro push), riceveremo un errore che ci avvisa che dobbiamo fare prima un `git pull` per sincronizzare il nostro lavoro.
|
||||
|
||||
---
|
||||
|
||||
### **Pull**
|
||||
|
||||
**`git pull`** è il comando che ci permette di scaricare e integrare le modifiche dal repository remoto al nostro repository locale. È una combinazione di due comandi: **`git fetch`** (scarica i cambiamenti dal remoto) e **`git merge`** (integra questi cambiamenti nel nostro branch attuale).
|
||||
|
||||
#### Come funziona:
|
||||
|
||||
1. Se altri collaboratori hanno fatto modifiche al repository remoto, possiamo ottenere queste modifiche con **`git pull`**. Questo comando aggiorna il nostro branch locale con le modifiche più recenti dal repository remoto.
|
||||
|
||||
2. Eseguiamo il comando:
|
||||
|
||||
```bash
|
||||
git pull origin main
|
||||
```
|
||||
|
||||
In questo caso, `origin` è il nome del repository remoto (il nome predefinito quando cloni un repository), e `main` è il branch che vogliamo aggiornare.
|
||||
|
||||
#### Cosa succede dietro le quinte:
|
||||
|
||||
- **`git fetch`** scarica tutte le modifiche dal repository remoto, ma non le integra ancora nel nostro codice.
|
||||
|
||||
- **`git merge`** unisce le modifiche scaricate al nostro branch attuale, risolvendo eventuali conflitti, se necessario.
|
||||
|
||||
#### Errori comuni:
|
||||
|
||||
- Se ci sono conflitti tra il nostro lavoro e quello degli altri, Git ci avviserà che dovremo risolverli manualmente. Dopo aver risolto i conflitti, dovremo aggiungere i file risolti (`git add`) e completare il merge con un commit.
|
||||
|
||||
## **7. Lavorare con branch**
|
||||
|
||||
### Creare un nuovo branch
|
||||
|
||||
Per creare un nuovo branch in Git, utilizziamo il comando:
|
||||
|
||||
```bash
|
||||
git branch <nome-branch>
|
||||
```
|
||||
|
||||
Sostituiamo `<nome-branch>` con il nome desiderato per il nuovo branch.
|
||||
|
||||
### Spostarsi su un branch
|
||||
|
||||
Per spostarci su un branch esistente, usiamo:
|
||||
|
||||
```bash
|
||||
git checkout <nome-branch>
|
||||
```
|
||||
|
||||
Oppure, per creare e spostarci su un nuovo branch in un solo comando:
|
||||
|
||||
```bash
|
||||
git switch -c <nome-branch>
|
||||
```
|
||||
|
||||
### Unire un branch nel branch principale
|
||||
|
||||
Per unire un branch nel branch principale (di solito chiamato `main`):
|
||||
|
||||
1. Spostiamoci sul branch principale:
|
||||
|
||||
```bash
|
||||
git checkout main
|
||||
```
|
||||
|
||||
2. Eseguiamo il merge del branch desiderato:
|
||||
|
||||
```bash
|
||||
git merge <nome-branch>
|
||||
```
|
||||
|
||||
Sostituiamo `<nome-branch>` con il nome del branch che vogliamo unire.
|
||||
|
||||
### Risoluzione dei conflitti
|
||||
|
||||
Quando due persone modificano lo stesso file, Git può generare un conflitto. Ecco come risolverlo:
|
||||
|
||||
1. Identifichiamo il file in conflitto:
|
||||
|
||||
```bash
|
||||
git status
|
||||
```
|
||||
|
||||
2. Modifichiamo manualmente il file per risolvere il conflitto. Cerchiamo i segni di conflitto (`<<<<<<<`, `=======`, `>>>>>>>`) e scegliamo quali modifiche mantenere.
|
||||
|
||||
3. Aggiungiamo il file risolto allo stage:
|
||||
|
||||
```bash
|
||||
git add <file>
|
||||
```
|
||||
|
||||
4. Concludiamo con un commit per salvare le modifiche risolte:
|
||||
|
||||
```bash
|
||||
git commit
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## **9. Comandi utili**
|
||||
|
||||
### **Visualizzare le differenze**
|
||||
|
||||
```bash
|
||||
git diff
|
||||
```
|
||||
|
||||
### **Annullare modifiche**
|
||||
|
||||
1. **Prima del commit**:
|
||||
|
||||
```bash
|
||||
git checkout -- <file>
|
||||
```
|
||||
|
||||
2. **Dopo il commit**:
|
||||
|
||||
```bash
|
||||
git reset --soft HEAD~1
|
||||
```
|
||||
|
||||
### **Eliminare un branch**
|
||||
|
||||
```bash
|
||||
git branch -d <nome-branch>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## **10. Best practices**
|
||||
|
||||
- Scriviamo messaggi di commit chiari e descrittivi.
|
||||
|
||||
- Creiamo branch per nuove funzionalità o bugfix.
|
||||
|
||||
- Sincronizziamo frequentemente il nostro repository locale con quello remoto.
|
||||
|
||||
---
|
||||
|
||||
## **11. Risorse aggiuntive**
|
||||
|
||||
- [Documentazione ufficiale di Git](https://git-scm.com/doc)
|
||||
|
||||
- [Guida interattiva Learn Git Branching](https://learngitbranching.js.org/)
|
||||
|
||||
- [GitHub Docs](https://docs.github.com/)
|
@ -1,80 +0,0 @@
|
||||
---
|
||||
id: pagina-poisson-con-astro
|
||||
title: Pagina Poisson con Astro
|
||||
description: Vediamo come creare una pagina Poisson moderna ⚡ con Astro
|
||||
author: Antonio De Lucreziis
|
||||
tags: [astro, website]
|
||||
---
|
||||
|
||||
In questa guida vedremo come creare una pagina Poisson moderna utilizzando Astro, un nuovo framework di sviluppo web statico. Per prima cosa installeremo NodeJS sul nostro computer, poi creeremo un nuovo progetto Astro e infine dopo averlo generato, lo caricheremo su Poisson.
|
||||
|
||||
## Setup
|
||||
|
||||
Se siete sul vostro pc installate VSCode ed il plugin di Astro.
|
||||
|
||||
Poi installiamo NodeJS (se siete su Windows è consigliato [installare WSL con `wsl --install`](https://learn.microsoft.com/en-us/windows/wsl/install) e poi installare i seguenti pacchetti nell'ambiente Linux)
|
||||
|
||||
> NodeJS: https://nodejs.org/en/download/package-manager
|
||||
|
||||
```bash
|
||||
curl -fsSL https://fnm.vercel.app/install | bash
|
||||
source ~/.bashrc
|
||||
|
||||
fnm use --install-if-missing 20
|
||||
node -v
|
||||
npm -v
|
||||
```
|
||||
|
||||
## Creazione di un nuovo progetto Astro
|
||||
|
||||
Per prima cosa dobbiamo creare un nuovo progetto di Astro sul nostro computer, possiamo scegliere [uno dei tanti temi disponibili per Astro](https://astro.build/themes/) o partire da un blog di esempio con il seguente comando:
|
||||
|
||||
```bash
|
||||
npm create astro@latest -- --template blog
|
||||
cd nome-del-progetto
|
||||
npm install
|
||||
```
|
||||
|
||||
Se ad esempio volessimo usare un tema come "[Astro Nano](https://github.com/markhorn-dev/astro-nano)" possiamo fare così:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/markhorn-dev/astro-nano sito-poisson
|
||||
cd sito-poisson
|
||||
npm install
|
||||
```
|
||||
|
||||
L'ultima cosa importante che c'è da cambiare è che le pagine Poisson sono hostate su `https://poisson.phc.dm.unipi.it/~nomeutente/` che non è la radice del dominio del sito. Quindi dobbiamo cambiare il file `astro.config.mjs`:
|
||||
|
||||
```javascript
|
||||
export default defineConfig({
|
||||
...
|
||||
base: '/~nomeutente/',
|
||||
trailingSlash: 'always',
|
||||
...
|
||||
});
|
||||
```
|
||||
|
||||
## Lavorare con Astro
|
||||
|
||||
Per vedere il nostro progetto in locale possiamo eseguire il comando:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
A questo punto in base al tema scelto possiamo modificare i file dentro `src/pages` per cambiare il contenuto delle pagine. Molti temi sono preimpostati per scrivere contenuti in Markdown, ad esempio per il _template blog_ possiamo scrivere gli articoli per il nostro blog in `src/content/blog/{nome_post}.md`.
|
||||
|
||||
## Appunti
|
||||
|
||||
Una volta creato il progetto possiamo caricare appunti e dispense nella cartella `/public`
|
||||
|
||||
## Deploy
|
||||
|
||||
Per caricare il nostro sito su Poisson possiamo usare il comando `rsync`:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
rsync -avz dist/ username@poisson.phc.dm.unipi.it:public_html/
|
||||
```
|
||||
|
||||
Dove `username` è il nostro username Poisson. Da notare che gli `/` alla fine di `dist/` e `public_html/` sono importanti per evitare di creare delle cartelle per errore.
|
@ -1,111 +0,0 @@
|
||||
---
|
||||
id: deploy-with-github-actions
|
||||
title: Deploy automatico per Poisson da GitHub
|
||||
description: Come impostare il deploy automatico per la propria pagina Poisson tramite le GitHub Actions
|
||||
author: Antonio De Lucreziis
|
||||
tags: [github, poisson, sito]
|
||||
---
|
||||
|
||||
Supponiamo di avere un sito web statico che vogliamo caricare su Poisson, ad esempio un progetto NodeJS che genera in `dist/` o `out/` i file da caricare. Come possiamo automatizzare il processo di deploy su Poisson?
|
||||
|
||||
Vedremo come deployare il nostro sito, e successivamente come automatizzare il deployment con le GitHub Actions.
|
||||
|
||||
## Setup manuale
|
||||
|
||||
Come primo approccio, potremmo compilare il nostro progetto in locale e poi caricare i file su Poisson utilizzando `rsync`, ad esempio come segue:
|
||||
|
||||
```bash
|
||||
$ npm run build
|
||||
$ rsync -avz dist/ <username>@poisson.phc.dm.unipi.it:public_html/
|
||||
```
|
||||
|
||||
(osserviamo che gli `/` alla fine di `dist/` e `public_html/` sono importanti per evitare di creare delle cartelle per errore)
|
||||
|
||||
## GitHub Actions
|
||||
|
||||
Per automatizzare questo processo possiamo caricare il nostro progetto su GitHub ed aggiungere un _workflow_ che esegue il build e il deploy ogni volta che facciamo un push sul branch `main`. Ad esempio, possiamo creare un file `.github/workflows/deploy-poison.yaml` con quanto segue:
|
||||
|
||||
```yaml
|
||||
name: Deploy to Poisson
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Write SSH keys
|
||||
run: |
|
||||
install -m 600 -D /dev/null ~/.ssh/known_hosts
|
||||
install -m 600 -D /dev/null ~/.ssh/id_ed25519
|
||||
echo "${{ secrets.SSH_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
|
||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: '23'
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- name: Deploy
|
||||
run: rsync -cavz dist/ ${{ secrets.SSH_USER }}@poisson.phc.dm.unipi.it:public_html/
|
||||
```
|
||||
|
||||
## Comando rsync
|
||||
|
||||
Il comando `rsync` ha le seguenti opzioni:
|
||||
|
||||
- `-c` per controllare i file tramite checksum invece che per data e dimensione (che sono sempre diverse visto che stiamo ricosruendo il sito ogni volta con le GitHub Actions)
|
||||
|
||||
- `-a` per copiare ricorsivamente i file e mantenere i permessi
|
||||
|
||||
- `-v` per mostrare i file copiati
|
||||
|
||||
- `-z` per comprimere i file durante il trasferimento
|
||||
|
||||
## SSH Segreti
|
||||
|
||||
Per stabilire una connessione SSH a Poisson dalle GitHub Actions in modo sicuro, dobbiamo aggiungere alcuni segreti alla nostra repository. Vediamo meglio il workflow:
|
||||
|
||||
```yaml
|
||||
- name: Write SSH keys
|
||||
run: |
|
||||
install -m 600 -D /dev/null ~/.ssh/known_hosts
|
||||
install -m 600 -D /dev/null ~/.ssh/id_ed25519
|
||||
echo "${{ secrets.SSH_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
|
||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
|
||||
```
|
||||
|
||||
Questa è la parte più importante del workflow, che permette di autenticarsi su Poisson senza dover inserire la password ogni volta (cosa che non possiamo materialmente fare dall GitHub Actions).
|
||||
|
||||
Per farlo, creiamo in locale una coppia di chiavi SSH apposta per le GitHub Actions e aggiungiamo la chiave pubblica su Poisson. Per farlo, possiamo seguire questi passaggi:
|
||||
|
||||
```bash
|
||||
$ ssh-keygen -t ed25519 -C "deploy@github-actions" -f actions-deploy-key
|
||||
$ ssh-copy-id -i actions-deploy-key <username>@poisson.phc.dm.unipi.it
|
||||
```
|
||||
|
||||
Qui generiamo una chiave ssh utilizzando l'algoritmo `ed25519` (leggermente più consigliato rispetto a `rsa`, in particolare ha anche chiavi più corte), `-C` aggiunge semplicemente un commento alla chiave e `-f` specifica il file in cui salvare la chiave.
|
||||
|
||||
Poi eseguendo `cat actions-deploy-key` possiamo copiare il contenuto della chiave privata ed aggiungiamo il contenuto in un segreto chiamato `SSH_PRIVATE_KEY` nella nostra repository GitHub.
|
||||
|
||||
Poi, per evitare che la connessione venga rifiutata, eseguiamo in locale anche uno scan delle chiavi SSH di Poisson:
|
||||
|
||||
```bash
|
||||
$ ssh-keyscan poisson.phc.dm.unipi.it
|
||||
```
|
||||
|
||||
(se l'output è vuoto riprovare con `ssh-keyscan -4 ...`) e copiamo l'output in un segreto della nostra repository chiamato `SSH_KNOWN_HOSTS`.
|
||||
|
||||
Infine possiamo aggiungere anche un segreto `SSH_USER` con il nostro username o modificare anche direttamente il workflow ed inserire l'username direttamente nel file.
|
||||
|
||||
Ora ogni volta che facciamo un push sul branch `main` il nostro sito verrà automaticamente costruito e caricato su Poisson!
|
@ -1,85 +0,0 @@
|
||||
---
|
||||
id: attivazione-poisson
|
||||
title: Come attivare il proprio account Poisson
|
||||
description: Guida all'attivazione dell'account Poisson, con istruzioni per il primo accesso e configurazione del proprio sito
|
||||
author: Luca Lombardo
|
||||
tags: [poisson, sito, ssh]
|
||||
---
|
||||
|
||||
Poisson è un server autogestito dalla comunità studentesca di matematica, da sempre gestito con cura dai membri del PHC. Ogni studentə ha la possibilità di attivare un account personale, che consente l'accesso alla macchina via SSH e la creazione di uno spazio web personale.
|
||||
|
||||
## Come richiedere un account
|
||||
|
||||
Se non si è mai creato un account Poisson, è necessario inviare una richiesta via email a **macchinisti@lists.dm.unipi.it** includendo:
|
||||
|
||||
- Nome
|
||||
|
||||
- Cognome
|
||||
|
||||
- Username di ateneo (quello associato alla propria email istituzionale)
|
||||
|
||||
Nella mail è sufficiente specificare che si desidera attivare un account Poisson. I "macchinisti" si occuperanno di attivare l'account il prima possibile.
|
||||
|
||||
### Come ottenere le credenziali
|
||||
|
||||
Dopo l'attivazione, le credenziali del proprio account saranno disponibili accedendo al seguente sito:
|
||||
|
||||
<p align="center">
|
||||
<a href="https://credenziali.phc.dm.unipi.it/">https://credenziali.phc.dm.unipi.it/</a>
|
||||
</p>
|
||||
|
||||
Assicuriamoci di accedere con le credenziali di ateneo per recuperare username e password assegnati.
|
||||
|
||||
## Primo accesso al server
|
||||
|
||||
Per accedere a Poisson via SSH, è necessario:
|
||||
|
||||
1. Aprire un terminale (su Linux/Mac) o utilizzare un client SSH come PuTTY (su Windows).
|
||||
|
||||
2. Eseguire il comando:
|
||||
|
||||
```bash
|
||||
ssh <username>@poisson.phc.dm.unipi.it
|
||||
```
|
||||
|
||||
Dove `<username>` è il proprio username che è stato fornito con le credenziali.
|
||||
|
||||
## Configurazione della pagina web
|
||||
|
||||
Dopo aver effettuato il primo accesso, è possibile configurare la propria pagina web personale. Nella home directory del proprio account, è presente una cartella `public_html` in cui è possibile inserire i file necessari per la propria pagina web.
|
||||
|
||||
Vediamo un piccolo esempio di file `index.html` che possiamo creare:
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Sergio Steffè</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Sergio Steffè</h1>
|
||||
<img
|
||||
src="https://people.cs.dm.unipi.it/steffe/sergio.jpg"
|
||||
alt="Foto di Sergio Steffè"
|
||||
style="max-width: 300px; border-radius: 10px;"
|
||||
/>
|
||||
<p>Ciao! Sono Sergio Steffè.</p>
|
||||
<p>
|
||||
Email:
|
||||
<a href="mailto:sergio.steffe@example.com">sergio.steffe@example.com</a>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
Una volta salvato il file `index.html` nella cartella `public_html`, sarà possibile visualizzarlo accedendo al seguente indirizzo:
|
||||
|
||||
https://poisson.phc.dm.unipi.it/~<username>
|
||||
|
||||
Dove `<username>` è il proprio username.
|
||||
|
||||
### Creazione di pagine web più complesse
|
||||
|
||||
Per creare pagine web più complesse, suggeriamo di utilizzare il framework [Astro](https://astro.build/), che permette di creare siti web statici in modo semplice e veloce. [Abbiamo scritto una guida](/guide/pagina-poisson-con-astro) su come iniziare a utilizzare Astro per creare la nostra pagina web e caricarla su Poisson.
|
@ -1,34 +0,0 @@
|
||||
---
|
||||
id: recupero-password
|
||||
title: MI SONO SCORDATO LA PASSWORD DI POISSON COME FACCIO ORA?
|
||||
description: Hai dimenticato la tua password Poisson? Niente paura, vediamo cosa fare! 💪
|
||||
author: Luca Lombardo
|
||||
tags: [poisson, password]
|
||||
---
|
||||
|
||||
Se per qualche strano motivo hai dimenticato la tua password Poisson, niente paura! La procedura è super semplice:
|
||||
|
||||
1. Scrivi una mail a **macchinisti@lists.dm.unipi.it**.
|
||||
|
||||
2. Nella mail, specifica il tuo nome, cognome, username di ateneo (quello della tua email istituzionale) e se lo ricordi, anche il tuo username Poisson.
|
||||
|
||||
3. Attendi pazientemente la risposta dei macchinisti, che ti resetteranno la password e ti invieranno una nuova.
|
||||
|
||||
E voilà, in un batter d'occhio sarai di nuovo pronto a entrare nel fantastico mondo di Poisson.
|
||||
|
||||
## Template Email di Recupero
|
||||
|
||||
**Oggetto**: Recupero Password Poisson
|
||||
|
||||
```
|
||||
Salve,
|
||||
sono NOME COGNOME, la mia email istituzionale è
|
||||
N.COGNOME@studenti.unipi.it {ed il mio username Poisson
|
||||
è USERNAME / ma non ricordo il mio username Poisson}.
|
||||
|
||||
Grazie mille!
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**Nota:** Non preoccuparti, capita a tutti di dimenticare una password ogni tanto. Se vuoi evitare che succeda di nuovo, prova ad usare un password manager come [Bitwarden](https://bitwarden.com/) 😉
|
@ -1,68 +0,0 @@
|
||||
---
|
||||
id: eliminare-sito-poisson
|
||||
title: Come tolgo la mia pagina Poisson da Google?
|
||||
description: Sei divenuto troppo famoso 🤩 e vuoi eliminare la tua pagina Poisson dai risultati di ricerca di Google? Ecco come farlo!
|
||||
author: Antonio De Lucreziis
|
||||
tags: [poisson, sito]
|
||||
---
|
||||
|
||||
Hai un nuovo sito web e vuoi che venga indicizzato da Google prima della tua pagina Poisson? Oppure sei diventato troppo famoso, e vuoi eliminare la tua pagina Poisson dai risultati di ricerca di Google? In entrambi i casi, vediamo come fare.
|
||||
|
||||
Ricorda che la tua pagina Poisson è indicizzata da Google in quanto pubblicamente accessibile. Per "toglierla" dai risultati di ricerca dovremo chiedere a Google di non indicizzarla più, e quindi innanzitutto dire a Google che siamo i proprietari di quella pagina (altrimenti non ci permetterà di rimuoverla).
|
||||
|
||||
> **Attenzione**: in questo articolo, sostituisci sempre `USERNAME` con il tuo username Poisson (non `n.cognome`, quello è il tuo username di Ateneo).
|
||||
|
||||
## Cancellazione pagina Poisson
|
||||
|
||||
Invece di eliminare la tua pagina Poisson, puoi anche solo ridirezionarla al tuo nuovo sito web. Se fossi proprio sicuro di volerla eliminare, vediamo ora come fare.
|
||||
|
||||
A questo punto, se vogliamo anche eliminare tutta la pagina Poisson, possiamo farlo con il comando
|
||||
|
||||
```bash
|
||||
$ ssh USERNAME@poisson.phc.dm.unipi.it
|
||||
$ cd public_html
|
||||
$ rm -rf *
|
||||
```
|
||||
|
||||
> **Attenzione!** La cartella `public_html` nella propria home in realtà è un **link simbolico** alla cartella `public_html`, che fisicamente sta altrove. Per sostituire o cancellare il contenuto della propria pagina Poisson, dovremo eliminare tutti i file contenuti nella cartella `public_html`, _ma non la cartella stessa_.
|
||||
|
||||
## Google Search Console
|
||||
|
||||
### 1. Verifica della proprietà
|
||||
|
||||
Prima di tutto visita la pagina <https://search.google.com/search-console>, fai l'accesso con un account Google di tuo piacimento e clicca su "Aggiungi proprietà". Poisson utilizza la convenzione che le pagine personali sono raggiungibili all'indirizzo `https://poisson.phc.dm.unipi.it/~USERNAME`, quindi seleziona l'opzione "Prefisso URL" / "URL prefix" per poi inserire l'URL della tua pagina Poisson (es. `https://poisson.phc.dm.unipi.it/~USERNAME`).
|
||||
|
||||
Dopo una breve attesa, Google ci chiederà di verificare la nostra proprietà con alcuni metodi. Il metodo più semplice è quello di inserire un file di verifica nella nostra cartella pubblica. Scarica il file di verifica e copialo nella tua cartella pubblica: se ad esempio il file si chiama `google1234567890.html`, puoi caricarlo nella tua cartella pubblica con il seguente comando ([clicca QUI se non ricordi le credenziali](/guide/recupero-password)):
|
||||
|
||||
```bash
|
||||
# Vai nella cartella in cui hai scaricato il file di verifica
|
||||
$ ls
|
||||
... google1234567890.html ...
|
||||
|
||||
# Copia il file nella public_html su Poisson
|
||||
$ scp google1234567890.html USERNAME@poisson.phc.dm.unipi.it:public_html/
|
||||
```
|
||||
|
||||
Dopo qualche minuto, torniamo su Google Search Console e clicchiamo su "Verifica". Se tutto è andato a buon fine, Google ci darà accesso ai dati di indicizzazione della nostra pagina Poisson.
|
||||
|
||||
### 2. Richiesta di Rimozione
|
||||
|
||||
Nella barra laterale di sinistra, nella sezione "Indicizzazione", clicchiamo su "Rimozioni", dopodichè in "Rimozioni Temporanee" clicchiamo su "Nuova Richiesta" e selezioniamo l'opzione "Rimuovi tutti gli URL con questo prefisso". Come prefisso, andiamo ad inserire `https://poisson.phc.dm.unipi.it/~USERNAME` per rimuovere la nostra pagina Poisson e tutte le sue sottopagine. Infine, clicchiamo su "Invia richiesta di rimozione" per confermare.
|
||||
|
||||
### 3. Attesa...
|
||||
|
||||
Considera che Google potrebbe metterci fino a qualche giorno per rimuovere le pagine indicizzate. Ben fatto! Ora la tua pagina Poisson non sarà più indicizzata da Google.
|
||||
|
||||
## Redirect
|
||||
|
||||
Se invece vuoi che la tua pagina Poisson rimandi al tuo nuovo sito web, puoi impostare un redirect. Per fare ciò, ti basterà creare un file `.htaccess` nella cartella `public_html/` della tua home con il seguente contenuto:
|
||||
|
||||
```apache
|
||||
RedirectMatch 307 /~USERNAME/.* https://www.mio-nuovo-sito.com/
|
||||
```
|
||||
|
||||
Qui, il codice `307` indica un redirect temporaneo; se sei sicuro di volere un redirect permanente puoi usare direttamente il codice `301` (la differenza tecnica tra i due è che il primo non salva la cache del redirect nel browser, mentre il secondo sì).
|
||||
|
||||
## Conclusioni
|
||||
|
||||
Per rimuovere la tua pagina Poisson dai risultati di ricerca di altri motori di ricerca come Bing, DuckDuckGo, ecc., bisogna seguire procedure simili. Se fosse proprio necessario scrivi pure a noi macchinisti, e ricorda sempre che la tua pagina Poisson è pubblica e accessibile a tutti, quindi non metterci cose che non vuoi che siano pubbliche.
|
@ -1,189 +0,0 @@
|
||||
import Container from '../../components/meta/Container.astro'
|
||||
import Palette from '../../components/meta/Palette.astro'
|
||||
|
||||
# Meta > Design
|
||||
|
||||
In questa pagina tento di spiegare come funziona il design di questo sito. I blocchi di codice con sfondo arancione chiaro sono esempi di codice Astro e sotto hanno un'anteprima del risultato _generata automaticamente_. Ad esempio
|
||||
|
||||
```astro
|
||||
<p>Questo è un paragrafo</p>
|
||||
```
|
||||
|
||||
Molti di questi esempi hanno alcuni stili impostati in `style` per mostrare come funzionano. Nella pratica invece è consigliato create una classe per ogni tipo di componente ed impostare le proprietà via CSS, ad esempio
|
||||
|
||||
```css
|
||||
.my-custom-form {
|
||||
--card-base: var(--palette-red);
|
||||
max-width: 25rem;
|
||||
}
|
||||
```
|
||||
|
||||
```html
|
||||
<div class="my-custom-form card">
|
||||
<p>Questo è un paragrafo</p>
|
||||
</div>
|
||||
```
|
||||
|
||||
## Card
|
||||
|
||||
Le card sono uno dei componenti più importanti di questo sito. Sono utilizzate per mostrare i post, i progetti e le pagine. Ecco alcuni esempi per dare un'idea
|
||||
|
||||
### Esempio di base
|
||||
|
||||
Una card semplice ha un titolo ed una descrizione.
|
||||
|
||||
```astro
|
||||
<div class="card" style="--card-base: var(--guide-base); max-width: 25rem;">
|
||||
<div class="title">Titolo</div>
|
||||
<div class="text">Descrizione lorem ipsum dolor sit amet consectetur adipisicing elit. Aspernatur, labore?</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
### Varianti
|
||||
|
||||
#### Grande
|
||||
|
||||
Le card possono essere di dimensioni diverse. Questa è una card grande.
|
||||
|
||||
```astro
|
||||
<div class="card large" style="--card-base: lightgreen; max-width: 25rem;">
|
||||
<div class="title">Titolo</div>
|
||||
<div class="text">Descrizione lorem ipsum dolor sit amet consectetur adipisicing elit. Aspernatur, labore?</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
### Low Level: Mixin SCSS
|
||||
|
||||
Non dovrebbe essere mai necessario usarlo direttamente ma l'effetto di ombra delle card è ottenuto con questo mixin SCSS (che si trova in `src/styles/mixins.scss`).
|
||||
|
||||
```scss
|
||||
@mixin neo-brutalist-card($size: 3px, $offset: $size + 1, $shadow: true, $hoverable: false) {
|
||||
border: $size solid #222;
|
||||
border-radius: $size * 2;
|
||||
|
||||
@if $shadow {
|
||||
box-shadow: $offset $offset 0 0 #222;
|
||||
}
|
||||
|
||||
@if $hoverable {
|
||||
transition: all 64ms linear;
|
||||
|
||||
&:hover {
|
||||
transform: translate(-1px, -1px);
|
||||
box-shadow: $offset + 1 $offset + 1 0 0 #222;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Ad esempio tutti i bottoni utilizzano direttamente questo mixin senza cambiare i parametri di default.
|
||||
|
||||
### Sotto-componenti
|
||||
|
||||
#### Titolo
|
||||
|
||||
```astro
|
||||
<div class="card">
|
||||
<div class="title">Titolo</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
#### Testo & Modificatori
|
||||
|
||||
Se c'è poco testo, può essere inserito direttamente nella card.
|
||||
|
||||
```astro
|
||||
<div class="card">
|
||||
<div class="text">Descrizione lorem ipsum dolor sit amet consectetur adipisicing elit. Aspernatur, labore?</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
Altrimenti può essere inserito in un tag `<p>`.
|
||||
|
||||
```astro
|
||||
<div class="card">
|
||||
<div class="text">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Distinctio, vel! Veritatis est sit beatae eveniet.
|
||||
</p>
|
||||
<p>
|
||||
Error, minus, asperiores quaerat nulla cumque, nisi ipsam assumenda consectetur accusamus tempore
|
||||
consequatur quae. Fugit?
|
||||
</p>
|
||||
<p>
|
||||
Quos sapiente amet numquam quis, libero odit eum, eius perspiciatis repellat nesciunt cupiditate asperiores
|
||||
maiores?
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
C'è anche il modificatore `small` e `dimmed` per ridurre la grandezza del testo e renderlo grigio rispettivamente.
|
||||
|
||||
```astro
|
||||
<div class="card" style="max-width: 25rem;">
|
||||
<div class="text">Some normal text, this is a very long text that should wrap on the next line</div>
|
||||
<div class="text small">This is some small text</div>
|
||||
<div class="text dimmed">This is some dimmed text</div>
|
||||
<div class="text small dimmed">This is some small dimmed text</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
#### Tags
|
||||
|
||||
I tag sono una lista di link con `display: flex` e `flex-wrap: wrap`.
|
||||
|
||||
```astro
|
||||
<div class="card" style="max-width: 25rem;">
|
||||
<div class="tags">
|
||||
<a href="#">#tag1</a>
|
||||
<a href="#">#tagg2</a>
|
||||
<a href="#">#tag3</a>
|
||||
<a href="#">#taggg4</a>
|
||||
<a href="#">#tagg5</a>
|
||||
<a href="#">#taggg6</a>
|
||||
<a href="#">#tag7</a>
|
||||
<a href="#">#taggg8</a>
|
||||
<a href="#">#tag9</a>
|
||||
<a href="#">#taggggg10</a>
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
## Palette
|
||||
|
||||
Varie sezioni del sito utilizzano diverse palette di colori. Questa è la palette di base.
|
||||
|
||||
### Guide
|
||||
|
||||
<Palette
|
||||
colors={[
|
||||
'var(--guide-base)',
|
||||
'var(--guide-darkest)',
|
||||
'var(--guide-darker)',
|
||||
'var(--guide-dark)',
|
||||
'var(--guide-light)',
|
||||
'var(--guide-lighter)',
|
||||
'var(--guide-lightest)',
|
||||
]}
|
||||
/>
|
||||
|
||||
## Combo Box
|
||||
|
||||
I combo box sono un componente per fare dropdown scritto in Preact. Questo è un esempio di come funzionano.
|
||||
|
||||
```js
|
||||
import { ComboBox } from '@/lib/components/ComboBox'
|
||||
|
||||
const [value, setValue] = useState('option-1')
|
||||
```
|
||||
|
||||
```jsx
|
||||
<ComboBox value={value} setValue={setValue}>
|
||||
{{
|
||||
'option-1': <>Option 1</>
|
||||
'option-2': <>Option 2</>
|
||||
'option-3': <>Option 3</>
|
||||
}}
|
||||
</ComboBox>
|
||||
```
|
@ -1,10 +0,0 @@
|
||||
---
|
||||
# Questo documento è utilizzato nella homepage del sito nella card principale
|
||||
title: Cos'è il PHC?
|
||||
---
|
||||
|
||||
Il <span class="highlighted" title="Pisa Happy Computing">**PHC**</span> è un laboratorio informatico nato nel 1999 e gestito dagli studenti del **Dipartimento di Matematica** di Pisa; per più informazioni sulla storia del PHC, vedi la [pagina dedicata](/storia).
|
||||
|
||||
La sede del PHC è la [stanza 106](https://www.dm.unipi.it/mappa/?sel=638cd24b50cf34e03924a00c) del Dipartimento, dove i <span class="highlighted" title="ovver gli studenti che gestiscono il PHC, vedi fine pagina">**macchinisti**</span> si ritrovano per realizzare progetti [hardware](http://steffe.cs.dm.unipi.it/) o [software](https://lab.phc.dm.unipi.it/orario) e per occuparsi di alcuni servizi per gli studenti, come il server [Poisson](https://poisson.phc.dm.unipi.it) che ospita le pagine degli studenti.
|
||||
|
||||
In PHC si usano principalmente sistemi operativi basati su <span class="highlighted" title="ma anche UNIX, Solaris, MacOS...">**Linux**</span>, ed i macchinisti sono grandi sostenitori del <a title="Free and Open Source Software" href="https://it.wikipedia.org/wiki/Free_and_Open_Source_Software">FOSS</a> (che loro stessi sviluppano sulla propria istanza [Gitea](https://git.phc.dm.unipi.it/phc)).
|