feat: header d'info sur chaque page
parent
a1dfc7b087
commit
275911b27c
|
@ -15,6 +15,7 @@ import { statsSocialesDesc } from "./statistiques/v2/sociales/StatsSociales";
|
||||||
import { checkDbSchemas } from "./notion/fetch/schemaCheck/checkDbSchemas";
|
import { checkDbSchemas } from "./notion/fetch/schemaCheck/checkDbSchemas";
|
||||||
import { computeSequencEvtPenalSankeyData } from "./statistiques/v2/penales/computeSankeyData";
|
import { computeSequencEvtPenalSankeyData } from "./statistiques/v2/penales/computeSankeyData";
|
||||||
import { sankeyDataToMermaidDiagram } from "./statistiques/v2/sankey/sankeyDataToMermaidDiagram";
|
import { sankeyDataToMermaidDiagram } from "./statistiques/v2/sankey/sankeyDataToMermaidDiagram";
|
||||||
|
import { formatDate } from "date-fns";
|
||||||
|
|
||||||
type ProcessOptions = {
|
type ProcessOptions = {
|
||||||
dryRun: boolean;
|
dryRun: boolean;
|
||||||
|
@ -111,21 +112,29 @@ function buildProcessOptions(): ProcessOptions {
|
||||||
console.log("Publishing statistics...");
|
console.log("Publishing statistics...");
|
||||||
await publishStatisticsToNotion(elStats, currentDate, notionClient);
|
await publishStatisticsToNotion(elStats, currentDate, notionClient);
|
||||||
|
|
||||||
|
const header = `
|
||||||
|
Note: Sauf mention contraire les statistiques sont basées sur les familles résistantes & ex-résistantes.
|
||||||
|
Dernière mise à jour le ${formatDate(currentDate, "dd/MM/yyyy à HH:mm")}
|
||||||
|
|
||||||
|
`;
|
||||||
await publishStatsToPage(
|
await publishStatsToPage(
|
||||||
notionClient,
|
notionClient,
|
||||||
"313751fb-daed-4b33-992f-c86d7ac2de37",
|
"313751fb-daed-4b33-992f-c86d7ac2de37",
|
||||||
|
header,
|
||||||
statsGeneralesDesc,
|
statsGeneralesDesc,
|
||||||
statsGenerales
|
statsGenerales
|
||||||
);
|
);
|
||||||
await publishStatsToPage(
|
await publishStatsToPage(
|
||||||
notionClient,
|
notionClient,
|
||||||
"969eac5c-a4eb-49d4-b4ad-c341c9c4c785",
|
"969eac5c-a4eb-49d4-b4ad-c341c9c4c785",
|
||||||
|
header,
|
||||||
statsPenalesDesc,
|
statsPenalesDesc,
|
||||||
statsPenales
|
statsPenales
|
||||||
);
|
);
|
||||||
await publishStatsToPage(
|
await publishStatsToPage(
|
||||||
notionClient,
|
notionClient,
|
||||||
"68a8c03a-a4a2-4ff3-b044-7c8dbbdc28ce",
|
"68a8c03a-a4a2-4ff3-b044-7c8dbbdc28ce",
|
||||||
|
header,
|
||||||
statsSocialesDesc,
|
statsSocialesDesc,
|
||||||
statsSociales
|
statsSociales
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
import { BlockObjectRequest } from "@notionhq/client/build/src/api-endpoints";
|
||||||
|
import {
|
||||||
|
isStatGroupDesc,
|
||||||
|
StatDesc,
|
||||||
|
StatGroupDesc,
|
||||||
|
StatsType,
|
||||||
|
} from "../../../statistiques/v2/desc/StatsDesc";
|
||||||
|
import { formatValue } from "../../../format/formatValue";
|
||||||
|
|
||||||
|
export function createStatGroupListItemBlock<D extends StatGroupDesc>(
|
||||||
|
descriptor: D,
|
||||||
|
stats: StatsType<D>
|
||||||
|
): BulletedListItemBlockObjectRequest {
|
||||||
|
return {
|
||||||
|
bulleted_list_item: {
|
||||||
|
rich_text: [
|
||||||
|
{
|
||||||
|
text: {
|
||||||
|
content: descriptor.label,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
children: createStatGroupChildrenListItemBlock(
|
||||||
|
descriptor,
|
||||||
|
stats
|
||||||
|
) as BulletedListItemChildren,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export type BulletedListItemBlockObjectRequest = Extract<
|
||||||
|
BlockObjectRequest,
|
||||||
|
{ bulleted_list_item: object }
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type BulletedListItemChildren =
|
||||||
|
BulletedListItemBlockObjectRequest["bulleted_list_item"]["children"];
|
||||||
|
|
||||||
|
export function createStatGroupChildrenListItemBlock<D extends StatGroupDesc>(
|
||||||
|
descriptor: D,
|
||||||
|
stats: StatsType<D>
|
||||||
|
): BulletedListItemBlockObjectRequest[] {
|
||||||
|
return Object.keys(descriptor.stats).map((statName) => {
|
||||||
|
const childStatDesc = descriptor.stats[statName];
|
||||||
|
const childStatValue = stats[statName];
|
||||||
|
|
||||||
|
return isStatGroupDesc(childStatDesc)
|
||||||
|
? createStatGroupListItemBlock(
|
||||||
|
childStatDesc,
|
||||||
|
childStatValue as StatsType<typeof childStatDesc>
|
||||||
|
)
|
||||||
|
: createStatListItemBlock(childStatDesc, childStatValue as number);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function createStatListItemBlock(
|
||||||
|
descriptor: StatDesc,
|
||||||
|
statValue: number
|
||||||
|
): BulletedListItemBlockObjectRequest {
|
||||||
|
return {
|
||||||
|
bulleted_list_item: {
|
||||||
|
rich_text: [
|
||||||
|
{
|
||||||
|
text: {
|
||||||
|
content:
|
||||||
|
descriptor.label + ": " + formatValue(statValue, descriptor),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,94 +1,40 @@
|
||||||
import { Client, isFullBlock } from "@notionhq/client";
|
import { Client } from "@notionhq/client";
|
||||||
import { BlockObjectRequest } from "@notionhq/client/build/src/api-endpoints";
|
|
||||||
import { formatValue } from "../../../format/formatValue";
|
|
||||||
import {
|
import {
|
||||||
isStatGroupDesc,
|
|
||||||
StatDesc,
|
|
||||||
StatGroupDesc,
|
StatGroupDesc,
|
||||||
StatsType,
|
StatsType,
|
||||||
} from "../../../statistiques/v2/desc/StatsDesc";
|
} from "../../../statistiques/v2/desc/StatsDesc";
|
||||||
import { listAllChildrenBlocks } from "../../utils/listAllChildrenBlocks";
|
import { createStatGroupChildrenListItemBlock } from "./createStatGroupListItemBlock";
|
||||||
import { removeBlocks } from "../../utils/removeBlocks";
|
import { updatePageContent } from "./updatePageContent";
|
||||||
|
import { BlockObjectRequest } from "@notionhq/client/build/src/api-endpoints";
|
||||||
|
|
||||||
export async function publishStatsToPage<D extends StatGroupDesc>(
|
export async function publishStatsToPage<D extends StatGroupDesc>(
|
||||||
notionClient: Client,
|
notionClient: Client,
|
||||||
statsPageId: string,
|
statsPageId: string,
|
||||||
|
pageHeader: string,
|
||||||
descriptor: D,
|
descriptor: D,
|
||||||
stats: StatsType<D>
|
stats: StatsType<D>
|
||||||
) {
|
) {
|
||||||
const childrenBlocks = (
|
const statsBlocks = createStatGroupChildrenListItemBlock(descriptor, stats);
|
||||||
await listAllChildrenBlocks(notionClient, {
|
|
||||||
block_id: statsPageId,
|
|
||||||
})
|
|
||||||
).filter(isFullBlock);
|
|
||||||
const blocksIdsToRemove = childrenBlocks.map((b) => b.id);
|
|
||||||
await removeBlocks(notionClient, blocksIdsToRemove);
|
|
||||||
|
|
||||||
const newBlocks = createStatGroupChildrenListItemBlock(descriptor, stats);
|
const textBlock = createParagraphBlock(pageHeader);
|
||||||
|
await updatePageContent(notionClient, statsPageId, [
|
||||||
await notionClient.blocks.children.append({
|
textBlock,
|
||||||
block_id: statsPageId,
|
...statsBlocks,
|
||||||
children: [...newBlocks],
|
]);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createStatGroupListItemBlock<D extends StatGroupDesc>(
|
type ParagraphBlockObjectRequest = Extract<
|
||||||
descriptor: D,
|
|
||||||
stats: StatsType<D>
|
|
||||||
): BulletedListItemBlockObjectRequest {
|
|
||||||
return {
|
|
||||||
bulleted_list_item: {
|
|
||||||
rich_text: [
|
|
||||||
{
|
|
||||||
text: {
|
|
||||||
content: descriptor.label,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
children: createStatGroupChildrenListItemBlock(
|
|
||||||
descriptor,
|
|
||||||
stats
|
|
||||||
) as BulletedListItemChildren,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
type BulletedListItemBlockObjectRequest = Extract<
|
|
||||||
BlockObjectRequest,
|
BlockObjectRequest,
|
||||||
{ bulleted_list_item: object }
|
{ paragraph: unknown }
|
||||||
>;
|
>;
|
||||||
|
|
||||||
type BulletedListItemChildren =
|
function createParagraphBlock(content: string): ParagraphBlockObjectRequest {
|
||||||
BulletedListItemBlockObjectRequest["bulleted_list_item"]["children"];
|
|
||||||
|
|
||||||
function createStatGroupChildrenListItemBlock<D extends StatGroupDesc>(
|
|
||||||
descriptor: D,
|
|
||||||
stats: StatsType<D>
|
|
||||||
): BulletedListItemBlockObjectRequest[] {
|
|
||||||
return Object.keys(descriptor.stats).map((statName) => {
|
|
||||||
const childStatDesc = descriptor.stats[statName];
|
|
||||||
const childStatValue = stats[statName];
|
|
||||||
|
|
||||||
return isStatGroupDesc(childStatDesc)
|
|
||||||
? createStatGroupListItemBlock(
|
|
||||||
childStatDesc,
|
|
||||||
childStatValue as StatsType<typeof childStatDesc>
|
|
||||||
)
|
|
||||||
: createStatListItemBlock(childStatDesc, childStatValue as number);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function createStatListItemBlock(
|
|
||||||
descriptor: StatDesc,
|
|
||||||
statValue: number
|
|
||||||
): BulletedListItemBlockObjectRequest {
|
|
||||||
return {
|
return {
|
||||||
bulleted_list_item: {
|
paragraph: {
|
||||||
rich_text: [
|
rich_text: [
|
||||||
{
|
{
|
||||||
text: {
|
text: {
|
||||||
content:
|
content: content,
|
||||||
descriptor.label + ": " + formatValue(statValue, descriptor),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { Client, isFullBlock } from "@notionhq/client";
|
||||||
|
import { BlockObjectRequest } from "@notionhq/client/build/src/api-endpoints";
|
||||||
|
import { listAllChildrenBlocks } from "../../utils/listAllChildrenBlocks";
|
||||||
|
import { removeBlocks } from "../../utils/removeBlocks";
|
||||||
|
|
||||||
|
export async function updatePageContent(
|
||||||
|
notionClient: Client,
|
||||||
|
notionPageId: string,
|
||||||
|
newBlocks: BlockObjectRequest[]
|
||||||
|
) {
|
||||||
|
const childrenBlocks = (
|
||||||
|
await listAllChildrenBlocks(notionClient, {
|
||||||
|
block_id: notionPageId,
|
||||||
|
})
|
||||||
|
).filter(isFullBlock);
|
||||||
|
const blocksIdsToRemove = childrenBlocks.map((b) => b.id);
|
||||||
|
await removeBlocks(notionClient, blocksIdsToRemove);
|
||||||
|
|
||||||
|
await notionClient.blocks.children.append({
|
||||||
|
block_id: notionPageId,
|
||||||
|
children: [...newBlocks],
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue