Skip to content

Commit

Permalink
Suppression de Nuxt Content.
Browse files Browse the repository at this point in the history
Inutilisable à cause du bug suivant : nuxt/content#3114.
  • Loading branch information
Skyost committed Feb 21, 2025
1 parent b089d7a commit 4cf83f3
Show file tree
Hide file tree
Showing 34 changed files with 2,696 additions and 4,834 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Install dependencies 👨🏻‍💻
run: npm ci
- name: Generate ⚙️
run: npm run generate
run: npx ts-to-zod types/lesson.d.ts types/lesson.z.ts && npm run generate
env:
GITHUB_CLIENT_ID: ${{ secrets.CLIENT_ID }}
GITHUB_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ sw.*
*.run.xml
.output
content/
types/lesson.z.ts
12 changes: 6 additions & 6 deletions components/Applications/Lessons/LessonsApplication.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const onFileLoaded = async (event: FileContent) => {
return
}
if (isFileNameValid(name)) {
if (isFilenameValid(name)) {
await saveFileContent(currentDirectory.value + name, event.content.split(',')[1])
await refreshFileList()
}
Expand All @@ -43,7 +43,7 @@ const createNewFile = async () => {
return
}
if (isFileNameValid(name)) {
if (isFilenameValid(name)) {
await saveFileContent(currentDirectory.value + name, '')
await refreshFileList()
}
Expand All @@ -58,7 +58,7 @@ const renameFile = async (file: APILessonsListEntry) => {
return
}
if (!isFileNameValid(name)) {
if (!isFilenameValid(name)) {
window.alert('Nom de fichier invalide !')
return
}
Expand Down Expand Up @@ -145,13 +145,13 @@ const request = async (callback: () => Promise<any>) => {
loading.value = false
}
const isFileNameValid = (fileName: string | null) => {
if (!fileName || fileName.includes('/') || !fileList.value) {
const isFilenameValid = (filename: string | null) => {
if (!filename || filename.includes('/') || !fileList.value) {
return false
}
for (const file of fileList.value) {
if (file.name === fileName) {
if (file.name === filename) {
return false
}
}
Expand Down
9 changes: 3 additions & 6 deletions components/CurrentCommitSha.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ withDefaults(defineProps<{
dataRepositoryLink: `https://github.com/${siteMeta.github.username}/${siteMeta.github.dataRepository}`
})
const { data: commitSha } = useLazyAsyncData(
'current-commit-sha',
() => queryContent('/latest-commit')
.findOne()
)
const { data: commitSha } = await useFetch('/_api/latest-commit.json')
// const { data: commitSha } = await useFetch(`/_api/latest-commit.json`)
const githubRepo = `https://github.com/${siteMeta.github.username}/${siteMeta.github.repository}`
</script>

Expand All @@ -21,7 +18,7 @@ const githubRepo = `https://github.com/${siteMeta.github.username}/${siteMeta.gi
Site web <a :href="`${githubRepo}/commit/${commitSha.websiteRepository.long}`">&#35;{{ commitSha.websiteRepository.short }}</a>.
Données <a :href="dataRepositoryLink">&#35;{{ commitSha.dataRepository.short }}</a>.
</span>
<span v-else>
<span v-else-if="commitSha.websiteRepository">
Révision <a :href="`${githubRepo}/commit/${commitSha.websiteRepository.long}`">&#35;{{ commitSha.websiteRepository.short }}</a>.
</span>
</span>
Expand Down
15 changes: 12 additions & 3 deletions components/ErrorDisplay.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
const props = defineProps<{
error: any,
error: any
changeTitle?: boolean
}>()
Expand All @@ -23,14 +23,23 @@ const title = computed(() => {
}
return 'Erreur'
})
const goBack = () => window.history.back()
</script>

<template>
<div>
<Title v-if="changeTitle">{{ title }}</Title>
<Title v-if="changeTitle">
{{ title }}
</Title>
<h1 v-text="title" />
<p>
Vous pouvez continuer votre navigation en allant sur <a href="javascript:history.back()">la page précédente</a> ou
Vous pouvez continuer votre navigation en allant sur <a
href="#"
@click.prevent="goBack"
>
la page précédente
</a> ou
en allant sur <nuxt-link to="/">la page d'accueil</nuxt-link>.
<span v-if="errorCode === 404">
Si quelque chose devait se trouver ici, n'hésitez pas à me contacter pour me le signaler.
Expand Down
6 changes: 3 additions & 3 deletions composables/useAccessToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { Ref } from 'vue'

/**
* Custom Vue composable to manage and retrieve the access token.
* @param {Date | undefined} expiration - Optional expiration date for the access token.
* @returns {Ref<string | null>} - The reactive reference to the access token.
* @param expiration Optional expiration date for the access token.
* @returns The reactive reference to the access token.
*/
export const useAccessToken = (expiration?: Date): Ref<string | null> => useCookie<string | null>(
'access_token',
Expand All @@ -18,7 +18,7 @@ export const useAccessToken = (expiration?: Date): Ref<string | null> => useCook

/**
* Custom Vue composable to generate authorization headers using the access token.
* @returns {Ref<{ Authorization: string }>} - The reactive reference to the authorization headers.
* @returns The reactive reference to the authorization headers.
*/
export const useAuthorizationHeaders = (): Ref<{ Authorization: string }> => computed(() => {
return {
Expand Down
12 changes: 4 additions & 8 deletions composables/useNavigationEntries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,33 @@ import type { Ref } from 'vue'

/**
* Represents an entry in the navigation tree.
* @interface
*/
export interface NavigationEntry {
/**
* Title of the navigation entry.
* @type {string}
*/
title: string

/**
* URL or route to navigate to.
* @type {string}
*/
to: string

/**
* Depth level of the navigation entry in the tree.
* @type {number}
*/
depth: number
}

/**
* Custom Vue composable to manage and retrieve navigation entries.
* @returns {Ref<NavigationEntry[]>} - The reactive reference to the navigation entries.
* @returns The reactive reference to the navigation entries.
*/
export const useNavigationEntries = (): Ref<NavigationEntry[]> => useState<NavigationEntry[]>('navigationEntries', () => [])

/**
* Custom Vue composable to add a new navigation entry.
* @param {NavigationEntry} newEntry - The new navigation entry to add.
* @param newEntry The new navigation entry to add.
*/
export const useNavigationEntry = (newEntry: NavigationEntry) => {
let endIndex
Expand All @@ -59,8 +55,8 @@ export const useNavigationEntry = (newEntry: NavigationEntry) => {

/**
* Determines whether a new navigation entry should be added.
* @param {NavigationEntry} newEntry - The new navigation entry to check.
* @returns {boolean} - Whether the new entry should be added.
* @param newEntry The new navigation entry to check.
* @returns Whether the new entry should be added.
*/
const shouldAddNavigationEntry = (newEntry: NavigationEntry): boolean => {
const entries = useNavigationEntries().value
Expand Down
9 changes: 9 additions & 0 deletions modules/commit-sha-file-generator/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* The storage key.
*/
export const storageKey = `commit-sha-file-generator`

/**
* The filename.
*/
export const filename = `latest-commit.json`
5 changes: 5 additions & 0 deletions modules/commit-sha-file-generator/handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { storageKey, filename } from './common.ts'

export default defineEventHandler(async () => {
return await useStorage(`assets:${storageKey}`).getItem(filename)
})
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import { execSync } from 'child_process'
import fs from 'fs'
import path from 'path'
import { createResolver, defineNuxtModule, useLogger } from '@nuxt/kit'
import { addServerHandler, createResolver, defineNuxtModule, useLogger } from '@nuxt/kit'
import { storageKey, filename } from './common.ts'

/**
* Options for the commit SHA file generator module.
*
* @interface
*/
export interface ModuleOptions {
/**
* The name of the file to store the latest commit information.
* The file target URL.
*/
fileName: string
targetUrl: string

/**
* The directory.
*/
directory: string
}

/**
* The name of the commit SHA file generator module.
*/
const name = 'commit-sha-file-generator'
export const name = 'commit-sha-file-generator'

/**
* The logger instance.
Expand All @@ -36,7 +40,8 @@ export default defineNuxtModule<ModuleOptions>({
compatibility: { nuxt: '^3.0.0' }
},
defaults: {
fileName: 'latest-commit.json'
targetUrl: '/_api/',
directory: `node_modules/.${name}/`
},
setup: (options, nuxt) => {
const resolver = createResolver(import.meta.url)
Expand All @@ -47,22 +52,39 @@ export default defineNuxtModule<ModuleOptions>({
const short = execSync('git rev-parse --short HEAD', { cwd: srcDir }).toString().trim()

// Merge with other data.
const latestCommitShaFile = resolver.resolve(srcDir, 'content', options.fileName)
const directoryPath = resolver.resolve(srcDir, options.directory)
const filePath = resolver.resolve(directoryPath, filename)
let latestCommitData = {
websiteRepository: { long, short }
}
if (fs.existsSync(latestCommitShaFile)) {
if (fs.existsSync(filePath)) {
latestCommitData = {
...JSON.parse(fs.readFileSync(latestCommitShaFile, { encoding: 'utf-8' })),
...JSON.parse(fs.readFileSync(filePath, { encoding: 'utf-8' })),
...latestCommitData
}
}

// Write commit information to file.
const filePath = resolver.resolve(srcDir, 'content', options.fileName)
fs.mkdirSync(path.dirname(filePath), { recursive: true })
fs.mkdirSync(directoryPath, { recursive: true })
fs.writeFileSync(filePath, JSON.stringify(latestCommitData))

logger.success(`Wrote latest commit info for ${long} in ${filePath}.`)

logger.info('Registering it to Nitro...')
nuxt.options.nitro.publicAssets = nuxt.options.nitro.publicAssets || []
nuxt.options.nitro.publicAssets.push({
baseURL: options.targetUrl,
dir: directoryPath,
fallthrough: true
})
nuxt.options.nitro.serverAssets = nuxt.options.nitro.serverAssets || []
nuxt.options.nitro.serverAssets.push({
baseName: storageKey,
dir: directoryPath
})
addServerHandler({
route: `${options.targetUrl}${path.parse(filePath).base}`,
handler: resolver.resolve(`./handler.ts`)
})
logger.success(`Done : "${options.targetUrl}" mapped to "${filePath}".`)
}
})
Loading

0 comments on commit 4cf83f3

Please sign in to comment.