Mat
Mat
CDCloudflare Developers
Created by Amadeus Pagel on 8/30/2023 in #pages-help
Github Automatic Deployments not working right now?
Quick Tip: Select Project -> Settings -> Builds & deployments -> Deploy hooks -> Add deploy hook Make a POST request to the received link
13 replies
CDCloudflare Developers
Created by Amadeus Pagel on 8/30/2023 in #pages-help
Github Automatic Deployments not working right now?
13 replies
CDCloudflare Developers
Created by Mat on 2/8/2023 in #pages-discussions
Fix trailing slash on pages
I used the solution that was given here: https://electricui.com/blog/switching-to-cloudflare-pages#how-to-disable-the-trailing-slash-on-cloudflare-pages If you don't have the ability to use Linux-level commands, you can use a simple JavaScript script and run it after generating your page
const fs = require('fs');
const path = require('path');

const baseDir = '<static location>';
const mainDirectoryName = '<set directory main name>';

const getFiles = (dir) => {
const files = [];
fs.readdirSync(dir).forEach((file) => {
const filePath = path.join(dir, file);
const stat = fs.lstatSync(filePath);
if (stat.isFile()) {
files.push(filePath);
} else if (stat.isDirectory()) {
files.push(...getFiles(filePath));
}
});
return files;
};

console.log('Start mover');
const allFiles = getFiles(baseDir);
allFiles.forEach((filePath) => {
if (path.extname(filePath) === '.html' && filePath.split(path.sep).length >= 1) {
const parent = path.dirname(filePath);
if (path.basename(parent) !== mainDirectoryName) {
const newPath = path.join(parent, '..', path.basename(parent) + '.html');
fs.renameSync(filePath, newPath);
}
}
});
console.log('Finality mover');
const fs = require('fs');
const path = require('path');

const baseDir = '<static location>';
const mainDirectoryName = '<set directory main name>';

const getFiles = (dir) => {
const files = [];
fs.readdirSync(dir).forEach((file) => {
const filePath = path.join(dir, file);
const stat = fs.lstatSync(filePath);
if (stat.isFile()) {
files.push(filePath);
} else if (stat.isDirectory()) {
files.push(...getFiles(filePath));
}
});
return files;
};

console.log('Start mover');
const allFiles = getFiles(baseDir);
allFiles.forEach((filePath) => {
if (path.extname(filePath) === '.html' && filePath.split(path.sep).length >= 1) {
const parent = path.dirname(filePath);
if (path.basename(parent) !== mainDirectoryName) {
const newPath = path.join(parent, '..', path.basename(parent) + '.html');
fs.renameSync(filePath, newPath);
}
}
});
console.log('Finality mover');
2 replies