update hugo modules and packages, and minimum hugo version required

This commit is contained in:
Somrat
2024-11-27 09:36:34 +06:00
parent b5c6d3aa76
commit 8fde71d68e
11 changed files with 69 additions and 70 deletions

View File

@@ -15,8 +15,8 @@ const toggleComment = ({ filepath, regex }) => {
);
fs.writeFileSync(filepath, updatedContent, "utf8");
} else {
const hasBreakline = matchedContent.includes("\n");
if (hasBreakline) {
const hasLineBreak = matchedContent.includes("\n");
if (hasLineBreak) {
const content = matchedContent
.split("\n")
.map((line) => "# " + line)
@@ -28,8 +28,8 @@ const toggleComment = ({ filepath, regex }) => {
}
};
const getFolderName = (rootfolder) => {
const configPath = path.join(rootfolder, "exampleSite/hugo.toml");
const getFolderName = (rootFolder) => {
const configPath = path.join(rootFolder, "exampleSite/hugo.toml");
const getConfig = fs.readFileSync(configPath, "utf8");
const match = getConfig.match(/theme\s*=\s*\[?"([^"\]]+)"\]?/);
let selectedTheme = null;
@@ -45,8 +45,8 @@ const deleteFolder = (folderPath) => {
}
};
const createNewfolder = (rootfolder, folderName) => {
const newFolder = path.join(rootfolder, folderName);
const createNewFolder = (rootFolder, folderName) => {
const newFolder = path.join(rootFolder, folderName);
fs.mkdirSync(newFolder, { recursive: true });
return newFolder;
};
@@ -56,7 +56,7 @@ const iterateFilesAndFolders = (rootFolder, { destinationRoot }) => {
const items = fs.readdirSync(directory, { withFileTypes: true });
items.forEach((item) => {
if (item.isDirectory()) {
createNewfolder(destinationRoot, item.name);
createNewFolder(destinationRoot, item.name);
iterateFilesAndFolders(path.join(directory, item.name), {
currentFolder: item.name,
destinationRoot: path.join(destinationRoot, item.name),
@@ -70,17 +70,17 @@ const iterateFilesAndFolders = (rootFolder, { destinationRoot }) => {
};
const setupProject = () => {
const rootfolder = path.join(__dirname, "../");
if (!fs.existsSync(path.join(rootfolder, "themes"))) {
const rootFolder = path.join(__dirname, "../");
if (!fs.existsSync(path.join(rootFolder, "themes"))) {
// remove this part if you don't using theme demo as a module
[
{
filepath: path.join(rootfolder, "exampleSite/hugo.toml"),
filepath: path.join(rootFolder, "exampleSite/hugo.toml"),
regex: /^.*theme\s*=\s*("[^"\]]+"|\S+)/m,
},
{
filepath: path.join(
rootfolder,
rootFolder,
"exampleSite/config/_default/module.toml",
),
regex: /\[\[imports\]\]\s*\r?\npath = "([^"]+)"/,
@@ -88,15 +88,15 @@ const setupProject = () => {
].forEach(toggleComment);
const folderList = ["layouts", "assets", "static"];
const folderName = getFolderName(rootfolder);
const newfolderName = createNewfolder(
path.join(rootfolder, "themes"),
const folderName = getFolderName(rootFolder);
const newFolderName = createNewFolder(
path.join(rootFolder, "themes"),
folderName,
);
folderList.forEach((folder) => {
const source = path.join(rootfolder, folder);
const destination = path.join(newfolderName, folder);
const source = path.join(rootFolder, folder);
const destination = path.join(newFolderName, folder);
if (fs.existsSync(source)) {
fs.mkdirSync(destination, { recursive: true });
iterateFilesAndFolders(source, {
@@ -107,8 +107,8 @@ const setupProject = () => {
}
});
const exampleSite = path.join(rootfolder, "exampleSite");
iterateFilesAndFolders(exampleSite, { destinationRoot: rootfolder });
const exampleSite = path.join(rootFolder, "exampleSite");
iterateFilesAndFolders(exampleSite, { destinationRoot: rootFolder });
deleteFolder(exampleSite);
}
};

View File

@@ -9,8 +9,8 @@ const toggleComment = ({ filepath, regex }) => {
const matchedContent = match[0];
const hasComment = matchedContent.startsWith("# ");
if (hasComment) {
const hasBreakline = matchedContent.includes("\n");
if (hasBreakline) {
const hasLineBreak = matchedContent.includes("\n");
if (hasLineBreak) {
updatedContent = updatedContent.replace(
regex,
matchedContent.replace(/# /gm, ""),
@@ -24,8 +24,8 @@ const toggleComment = ({ filepath, regex }) => {
}
};
const createNewfolder = (rootfolder, folderName) => {
const newFolder = path.join(rootfolder, folderName);
const createNewFolder = (rootFolder, folderName) => {
const newFolder = path.join(rootFolder, folderName);
fs.mkdirSync(newFolder, { recursive: true });
return newFolder;
};
@@ -36,8 +36,8 @@ const deleteFolder = (folderPath) => {
}
};
const getFolderName = (rootfolder) => {
const configPath = path.join(rootfolder, "exampleSite/hugo.toml");
const getFolderName = (rootFolder) => {
const configPath = path.join(rootFolder, "exampleSite/hugo.toml");
const getConfig = fs.readFileSync(configPath, "utf8");
const match = getConfig.match(/theme\s*=\s*\[?"([^"\]]+)"\]?/);
let selectedTheme = null;
@@ -52,7 +52,7 @@ const iterateFilesAndFolders = (rootFolder, { destinationRoot }) => {
const items = fs.readdirSync(directory, { withFileTypes: true });
items.forEach((item) => {
if (item.isDirectory()) {
createNewfolder(destinationRoot, item.name);
createNewFolder(destinationRoot, item.name);
iterateFilesAndFolders(path.join(directory, item.name), {
currentFolder: item.name,
destinationRoot: path.join(destinationRoot, item.name),
@@ -94,7 +94,7 @@ const setupTheme = () => {
"static",
];
const folder = createNewfolder(rootFolder, "exampleSite");
const folder = createNewFolder(rootFolder, "exampleSite");
fs.readdirSync(rootFolder, { withFileTypes: true }).forEach((file) => {
if (includesFiles.includes(file.name)) {