Skip to content

Commit

Permalink
fix non escaped characters causing build issues, added 404, updates t…
Browse files Browse the repository at this point in the history
…o github actions and temp disable auto build, move content up a level
  • Loading branch information
cadeluca committed Oct 22, 2024
1 parent 102c7f6 commit 4c1d7b9
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nextjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ name: Deploy Next.js site to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
#push:
# branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
35 changes: 0 additions & 35 deletions .github/workflows/update-db.yaml

This file was deleted.

52 changes: 52 additions & 0 deletions .github/workflows/update-tiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Update Tiles

on:
workflow_dispatch:

jobs:
update-db:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Detect package manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "manager=yarn" >> $GITHUB_OUTPUT
echo "command=install" >> $GITHUB_OUTPUT
echo "runner=yarn" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/package.json" ]; then
echo "manager=npm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
exit 0
else
echo "Unable to determine package manager"
exit 1
fi
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: Install Dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
- name: Generate DB
run: ${{ steps.detect-package-manager.outputs.runner }} npm run gen:db
env:
SERVICE_ACCOUNT_KEY: ${{ secrets.SERVICE_ACCOUNT_KEY }}
SPREADSHEET_ID: ${{ secrets.SPREADSHEET_ID }}
- name: Generate MDX
run: ${{ steps.detect-package-manager.outputs.runner }} npm run gen:mdx
- name: Commit Changes
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "[email protected]"
git add ./data/data.db
git add ./pages/tiles/*
git commit -m "Update tiles via GitHub Actions" || echo "No changes to commit"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.next
node_modules
src/pages/tiles
pages/tiles/*
.env
Binary file renamed src/data/data.db → data/data.db
Binary file not shown.
23 changes: 17 additions & 6 deletions src/data/generateMdxFiles.js → data/generateMdxFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import sqlite3 from "sqlite3";
import path from "path";

// todo: generate image if applicable?
const db = new sqlite3.Database("./src/data/data.db");
const db = new sqlite3.Database("./data/data.db");

async function fetchAndGenerateMdx() {
const tilesDir = path.join("./src/pages/tiles");
const tilesDir = path.join("./pages/tiles");
fs.rmSync(tilesDir, { recursive: true, force: true });
// should always be true
if (!fs.existsSync(tilesDir)) {
fs.mkdirSync(tilesDir, { recursive: true }); // Create the directory if it doesn't exist
fs.mkdirSync(tilesDir, { recursive: true });
}

db.all("SELECT * FROM tiles", (error, rows) => {
Expand All @@ -19,7 +21,7 @@ async function fetchAndGenerateMdx() {

rows.forEach((row) => {
const content = generateContent(row);
const cleansedFileName = row.name.replace(/[\/\\:*?"<>| ]/g, "_");
const cleansedFileName = row.name.replace(/[\/\\:*?"',!.<>| ]/g, "_");
const filePath = path.join(tilesDir, `${cleansedFileName}.mdx`);

fs.writeFile(filePath, content, (err) => {
Expand All @@ -34,9 +36,12 @@ async function fetchAndGenerateMdx() {
}

function generateContent(row) {
const escapedName = row.name;
// const escapedName = escapeQuotes(row.name);
// console.log(escapedName)

return `---
title: ${row.name}
sidebarTitle: ${row.name}
sidebarTitle: "${escapedName}"
---
temporary text:
Expand All @@ -45,4 +50,10 @@ ${row.id}
`;
}

function escapeQuotes(str) {
return str.replace(/['"]/g, (match) => {
return match === '"' ? '\\"' : "\\'";
});
}

fetchAndGenerateMdx();
2 changes: 1 addition & 1 deletion src/data/readCatalog.js → data/readCatalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dotenv.config();
// Setup SQLite Database
async function setupDatabase() {
return new Promise((resolve, reject) => {
const db = new sqlite3.Database("./src/data/data.db", (err) => {
const db = new sqlite3.Database("./data/data.db", (err) => {
if (err) {
return reject(err);
}
Expand Down
6 changes: 1 addition & 5 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import nextra from 'nextra'

const withNextra = nextra({
theme: 'nextra-theme-docs',
themeConfig: './src/theme.config.jsx',
latex: true,
search: {
codeblocks: false
}
themeConfig: './theme.config.jsx',
})

export default withNextra({
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"description": "Hextraction Catalog",
"type": "module",
"scripts": {
"gen:mdx": "node ./src/data/generateMdxFiles.js",
"gen:db": "node ./src/data/readCatalog.js",
"build": "npm run gen:db && npm run gen:mdx && next build",
"gen:mdx": "node ./data/generateMdxFiles.js",
"gen:db": "node ./data/readCatalog.js",
"build:full": "npm run gen:db && run gen:mdx && next build",
"build:lite": "next build",
"clean": "rimraf .next .turbo",
"dev": "next",
"start": "next start"
Expand Down
5 changes: 5 additions & 0 deletions pages/404.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { NotFoundPage } from "nextra-theme-docs";

# Page Not Found

<NotFoundPage />
3 changes: 3 additions & 0 deletions pages/_app.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions pages/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Gallery

todo
24 changes: 0 additions & 24 deletions src/components/Tags.js

This file was deleted.

6 changes: 0 additions & 6 deletions src/pages/_app.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/pages/index.mdx

This file was deleted.

4 changes: 0 additions & 4 deletions src/styles.css

This file was deleted.

File renamed without changes.

0 comments on commit 4c1d7b9

Please sign in to comment.