diff --git a/content/_meta.js b/content/_meta.js index 0dad753..de276b2 100644 --- a/content/_meta.js +++ b/content/_meta.js @@ -1,11 +1,4 @@ export default { - /** - * Do not remove the labels "Math Courses Start" - * and "Math Courses End" and "CSE Courses Start" and "CSE Courses End" - * or the separated builds will not work. - * - * WE USE THESE LABELS TO BUILD THE SEPARATED WEBSITES FOR MATH AND CSE COURSES. - */ menu: { title: 'Home', type: 'menu', @@ -24,43 +17,6 @@ export default { } }, }, - /* Load link with relative path */ - Math3200_link: { - title: 'Math3200', - type: 'page', - href: '/Math3200' - }, - Math429_link: { - title: 'Math429', - type: 'page', - href: '/Math429' - }, - Math4111_link: { - title: 'Math4111', - type: 'page', - href: '/Math4111' - }, - Math4121_link: { - title: 'Math4121', - type: 'page', - href: '/Math4121' - }, - Math4201_link: { - title: 'Math4201', - type: 'page', - href: '/Math4201' - }, - Math416_link: { - title: 'Math416', - type: 'page', - href: '/Math416' - }, - Math401_link: { - title: 'Math401', - type: 'page', - href: '/Math401' - }, - /* Math Courses Start */ Math3200: { title: 'Math3200', type: 'page', @@ -110,43 +66,6 @@ export default { timestamp: true, } }, - /* Math Courses End */ - CSE332S_link: { - title: 'CSE332S', - type: 'page', - href: '/CSE332S' - }, - CSE347_link: { - title: 'CSE347', - type: 'page', - href: '/CSE347' - }, - CSE442T_link: { - title: 'CSE442T', - type: 'page', - href: '/CSE442T' - }, - CSE5313_link: { - title: 'CSE5313', - type: 'page', - href: '/CSE5313' - }, - CSE510_link: { - title: 'CSE510', - type: 'page', - href: '/CSE510' - }, - CSE559A_link: { - title: 'CSE559A', - type: 'page', - href: '/CSE559A' - }, - CSE5519_link: { - title: 'CSE5519', - type: 'page', - href: '/CSE5519' - }, - /* CSE Courses Start */ CSE332S: { title: 'CSE332S', type: 'page', @@ -196,7 +115,6 @@ export default { timestamp: true, } }, - /* CSE Courses End */ Swap: { display: 'hidden', theme:{ diff --git a/distribute/prebuild.sh b/distribute/prebuild.sh new file mode 100644 index 0000000..fe8917c --- /dev/null +++ b/distribute/prebuild.sh @@ -0,0 +1,11 @@ +# This is pre-build script that cleans up resources and compiles for selected pages, then finally you may combine those subdirectories into one via nginx. + +echo 'Currently compiling pages: $KEEP_PAGES' + +# Rewrite base _meta.js and next.config.js for export pages +echo 'Rewrite base _meta.js and keeping $KEEP_PAGES' + +sed 's/(\w+\d+.):(\s*{\n.+\n.+)\n.+\n.+\n.+(\n.+},)/$1_link:$2\n href:'/$1'$3/g' -i ../content/_meta.js + +echo 'First step replaced file:' +cat ../content/_meta.js diff --git a/docker/Jenkinsfile b/docker/Jenkinsfile deleted file mode 100644 index 9de8ddc..0000000 --- a/docker/Jenkinsfile +++ /dev/null @@ -1,111 +0,0 @@ -pipeline { - environment { - registry = "trance0/notenextra" - version = "1.2" - NODE_OPTIONS = "--max-old-space-size=8192" - // NEXT_SEARCH_ALGOLIA_APP_ID = "${NEXT_SEARCH_ALGOLIA_APP_ID}" - // NEXT_SEARCH_ALGOLIA_API_KEY = "${NEXT_SEARCH_ALGOLIA_API_KEY}" - // NEXT_SEARCH_ALGOLIA_INDEX_NAME = "${NEXT_SEARCH_ALGOLIA_INDEX_NAME}" - } - - agent any - - stages { - stage("Cleanup Workspace") { - steps { - // Using Workspace Cleanup Plugin (if installed and configured) - cleanWs() - } - } - stage("Checkout") { - steps { - checkout([ - $class: "GitSCM", - branches: [[ name: "*/main" ]], - userRemoteConfigs: [[ - url: "https://github.com/Trance-0/NoteNextra", - ]] - ]) - } - } - stage("Build and test"){ - parallel { - stage("Build Math") { - steps { - script { - echo "Building docker image ${registry}-math:${version}.${env.BUILD_ID}" - def customImage = docker.build("${registry}-math:v${version}.${env.BUILD_ID}","-f ./docker/math/Dockerfile --no-cache --progress=plain .") - echo "Logging in to docker hub" - // docker.withRegistry("https://registry.hub.docker.com", "docker-hub-creds") { - // echo "Pushing docker image ${registry}:v${version}.${env.BUILD_ID}" - // customImage.push() - // } - echo "skipping push due to conflicted servers" - } - } - } - stage("Build CSE") { - steps { - script { - echo "Building docker image ${registry}-cse:${version}.${env.BUILD_ID}" - def customImage = docker.build("${registry}-cse:v${version}.${env.BUILD_ID}","-f ./docker/cse/Dockerfile --no-cache --progress=plain .") - echo "Logging in to docker hub" - // docker.withRegistry("https://registry.hub.docker.com", "docker-hub-creds") { - // echo "Pushing docker image ${registry}:v${version}.${env.BUILD_ID}" - // customImage.push() - // } - echo "skipping push due to conflicted servers" - } - } - } - } - } - stage("Cleanup Docker tags") { - steps { - script { - echo "1. Stopping existing container" - sh "docker compose -f ./docker/docker-compose.yaml down" - // Using Workspace Cleanup Plugin (if installed and configured) - echo "2. Removing existing images" - def imageNameMath = "${registry}-math:latest" - def imageNameCSE = "${registry}-cse:latest" - def oldImageIDMath = sh( - script: "docker images -qf reference=\${imageNameMath}", - returnStdout: true - ) - def oldImageIDCSE = sh( - script: "docker images -qf reference=\${imageNameCSE}", - returnStdout: true - ) - if ( "${oldImageIDMath}" != "" ) { - echo "Removing old image ${oldImageIDMath}" - echo "Image Name: " + "${imageNameMath}" - echo "Old Image: ${oldImageIDMath}" - sh "docker rmi ${oldImageIDMath}" - }else{ - echo "Warning: ${imageNameMath} does not exist" - } - if ( "${oldImageIDCSE}" != "" ) { - echo "Removing old image ${oldImageIDCSE}" - echo "Image Name: " + "${imageNameCSE}" - echo "Old Image: ${oldImageIDCSE}" - sh "docker rmi ${oldImageIDCSE}" - }else{ - echo "Warning: ${imageNameCSE} does not exist" - } - echo "3. Assigned new tags to the images" - sh "docker tag ${registry}-math:v${version}.${env.BUILD_ID} ${registry}-math:latest" - sh "docker tag ${registry}-cse:v${version}.${env.BUILD_ID} ${registry}-cse:latest" - } - } - } - stage("Deploy") { - steps { - script { - echo "Deploying docker image ${registry}-math:${version}.${env.BUILD_ID} and ${registry}-cse:${version}.${env.BUILD_ID} with docker compose" - sh "docker compose -f ./docker/docker-compose.yaml up -d" - } - } - } - } -} diff --git a/docker/cse/Dockerfile b/docker/cse/Dockerfile deleted file mode 100644 index 8f1b9ff..0000000 --- a/docker/cse/Dockerfile +++ /dev/null @@ -1,73 +0,0 @@ -# Dockerfile for Math folders - -# Source: https://github.com/vercel/next.js/blob/canary/examples/with-docker-multi-env/docker/production/Dockerfile -# syntax=docker.io/docker/dockerfile:1 - -FROM node:20-alpine AS base - -ENV NODE_OPTIONS="--max-old-space-size=8192" - -# 1. Install dependencies only when needed -FROM base AS deps -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. -RUN apk add --no-cache libc6-compat git - -WORKDIR /app - -# Install dependencies based on the preferred package manager -COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./ -RUN \ - if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ - elif [ -f package-lock.json ]; then npm ci; \ - elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i; \ - else echo "Lockfile not found, use default npm install" && npm i; \ - fi - -# 2. Rebuild the source code only when needed -FROM base AS builder -WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules -COPY . . -RUN ls -la - -# 2.1 Remove unnecessary files for build with title starting with CSE -RUN cd ./content && find . -maxdepth 1 -type d -name "Math*" -exec rm -rf {} + -RUN cd ./public && find . -maxdepth 1 -type d -name "Math*" -exec rm -rf {} + - -# 2.1.1 Check the updated folders -RUN cd ./content && ls -la -RUN cd ./public && ls -la - -# 2.2 Update the _meta.js files in the content folder -RUN sed -i '/\/\* Math Courses Start \*\//,/\/\* Math Courses End \*\//d' ./content/_meta.js - -# 2.2.1 Check the updated _meta.js file -RUN cat ./content/_meta.js - -# This will do the trick, use the corresponding env file for each environment. -# COPY .env.production.sample .env.production -RUN npm run build - -# 3. Production image, copy all the files and run next -FROM base AS runner -WORKDIR /app - -ENV NODE_ENV=production - -RUN addgroup -g 1001 -S nodejs -RUN adduser -S nextjs -u 1001 - -COPY --from=builder /app/public ./public - -# Automatically leverage output traces to reduce image size -# https://nextjs.org/docs/advanced-features/output-file-tracing -COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ -COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static - -USER nextjs - -EXPOSE 4200 - -ENV PORT=4200 - -CMD HOSTNAME="0.0.0.0" node server.js \ No newline at end of file diff --git a/docker/cse/test-build.sh b/docker/cse/test-build.sh deleted file mode 100644 index 770469d..0000000 --- a/docker/cse/test-build.sh +++ /dev/null @@ -1 +0,0 @@ -sudo docker build -t trance-0/notenextra-cse:v1.2.0 -f ./docker/cse/Dockerfile --no-cache --progress=plain . \ No newline at end of file diff --git a/docker/docker-compose-rebuild.sh b/docker/docker-compose-rebuild.sh deleted file mode 100644 index 9c43271..0000000 --- a/docker/docker-compose-rebuild.sh +++ /dev/null @@ -1 +0,0 @@ -docker compose -f docker/docker-compose.yaml up -d --build notenextra-math notenextra-cse \ No newline at end of file diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml deleted file mode 100644 index 9b1927f..0000000 --- a/docker/docker-compose.yaml +++ /dev/null @@ -1,33 +0,0 @@ -name: notenextra -services: - # you may need to update relative directories if you move this file - # default created directories is /docker/docker-compose.yaml - notenextra-math: - image: trance0/notenextra-math:latest - build: - context: ../ - dockerfile: ./docker/math/Dockerfile - tags: - - trance0/notenextra-math:latest - restart: on-failure:5 - ports: - - 13001:4200 - notenextra-cse: - image: trance0/notenextra-cse:latest - build: - context: ../ - dockerfile: ./docker/cse/Dockerfile - tags: - - trance0/notenextra-cse:latest - restart: on-failure:5 - ports: - - 13002:4200 - nginx: - image: nginx:latest - ports: - - 13000:80 - volumes: - - ./nginx.conf:/etc/nginx/nginx.conf - depends_on: - - notenextra-math - - notenextra-cse \ No newline at end of file diff --git a/docker/math/Dockerfile b/docker/math/Dockerfile deleted file mode 100644 index d612f1e..0000000 --- a/docker/math/Dockerfile +++ /dev/null @@ -1,73 +0,0 @@ -# Dockerfile for Math folders - -# Source: https://github.com/vercel/next.js/blob/canary/examples/with-docker-multi-env/docker/production/Dockerfile -# syntax=docker.io/docker/dockerfile:1 - -FROM node:20-alpine AS base - -ENV NODE_OPTIONS="--max-old-space-size=8192" - -# 1. Install dependencies only when needed -FROM base AS deps -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. -RUN apk add --no-cache libc6-compat git - -WORKDIR /app - -# Install dependencies based on the preferred package manager -COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./ -RUN \ - if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ - elif [ -f package-lock.json ]; then npm ci; \ - elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i; \ - else echo "Lockfile not found, use default npm install" && npm i; \ - fi - -# 2. Rebuild the source code only when needed -FROM base AS builder -WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules -COPY . . -RUN ls -la - -# 2.1 Remove unnecessary files for build with title starting with CSE -RUN cd ./content && find . -maxdepth 1 -type d -name "CSE*" -exec rm -rf {} + -RUN cd ./public && find . -maxdepth 1 -type d -name "CSE*" -exec rm -rf {} + - -# 2.1.1 Check the updated folders -RUN cd ./content && ls -la -RUN cd ./public && ls -la - -# 2.2 Update the _meta.js files in the content folder -RUN sed -i '/\/\* CSE Courses Start \*\//,/\/\* CSE Courses End \*\//d' ./content/_meta.js - -# 2.2.1 Check the updated _meta.js file -RUN cat ./content/_meta.js - -# This will do the trick, use the corresponding env file for each environment. -# COPY .env.production.sample .env.production -RUN npm run build - -# 3. Production image, copy all the files and run next -FROM base AS runner -WORKDIR /app - -ENV NODE_ENV=production - -RUN addgroup -g 1001 -S nodejs -RUN adduser -S nextjs -u 1001 - -COPY --from=builder /app/public ./public - -# Automatically leverage output traces to reduce image size -# https://nextjs.org/docs/advanced-features/output-file-tracing -COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ -COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static - -USER nextjs - -EXPOSE 4200 - -ENV PORT=4200 - -CMD HOSTNAME="0.0.0.0" node server.js \ No newline at end of file diff --git a/docker/math/test-build.sh b/docker/math/test-build.sh deleted file mode 100644 index f407689..0000000 --- a/docker/math/test-build.sh +++ /dev/null @@ -1 +0,0 @@ -sudo docker build -t trance-0/notenextra-math:v1.2.0 -f ./docker/math/Dockerfile --no-cache --progress=plain . \ No newline at end of file diff --git a/docker/nginx.conf b/docker/nginx.conf deleted file mode 100644 index 1e9903f..0000000 --- a/docker/nginx.conf +++ /dev/null @@ -1,102 +0,0 @@ - # Example for conf.d/default.conf -user www-data; -worker_processes 1; - -error_log /var/log/nginx/error.log; -pid /var/run/nginx.pid; - -events { - worker_connections 1024; -} - -http { - - upstream notenextra-math { - server notenextra-math:4200; - } - - upstream notenextra-cse { - server notenextra-cse:4200; - } - - # Decide where to send /_pagefind* based on the page that made the request - map $http_referer $load_upstream { - default http://notenextra-cse; - ~*://[^/]+/Math(?:/|$) http://notenextra-math; - ~*://[^/]+/CSE(?:/|$) http://notenextra-cse; - } - - - include /etc/nginx/mime.types; - - # add extra types - - types { - text/javascript mjs; - } - - default_type application/octet-stream; - - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - - access_log /var/log/nginx/access.log main; - - server { - listen 80; - server_name localhost; - - rewrite ^/.well-known/carddav /remote.php/dav/ permanent; - rewrite ^/.well-known/caldav /remote.php/dav/ permanent; - - location = /robots.txt { - allow all; - log_not_found off; - access_log off; - } - - # Send all next or additional assets (/_pagefind.js and /_pagefind/*) to the chosen app - # ^~ /_pagefind matches both "/_pagefind.js" and "/_pagefind/..." - location ^~ /_(.*)$ { - proxy_pass $load_upstream; # leaves URI intact (/_pagefind.js, /_pagefind/manifest.json, etc.) - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } - - location ~ ^/(build|tests|config|lib|3rdparty|templates|data)/ { - deny all; - } - - location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { - deny all; - } - - location ~ ^/Math(.*)$ { - proxy_pass http://notenextra-math/Math$1; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } - - location ~ ^/CSE(.*)$ { - proxy_pass http://notenextra-cse/CSE$1; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } - - location / { - proxy_pass http://notenextra-math; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } - - } -} \ No newline at end of file diff --git a/next.config.mjs b/next.config.mjs index 1ea75f9..43a4762 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -20,13 +20,14 @@ const bundleAnalyzer = withBundleAnalyzer({ }) export default bundleAnalyzer(withNextra({ - output: 'standalone', + // output: 'standalone', // static export start - // output: 'export', - // images: { - // unoptimized: true // mandatory, otherwise won't export - // }, + output: 'export', + images: { + unoptimized: true // mandatory, otherwise won't export + }, + basePath: '/', // static export end // eslint: {