diff --git a/.github/workflows/hugo.yml b/.github/workflows/hugo.yml index e8b7696..de53a57 100644 --- a/.github/workflows/hugo.yml +++ b/.github/workflows/hugo.yml @@ -16,8 +16,8 @@ permissions: # Environment variables available to all jobs and steps in this workflow env: HUGO_ENV: production - HUGO_VERSION: "0.114.0" - GO_VERSION: "1.16.3" + HUGO_VERSION: "0.115.1" + GO_VERSION: "1.20.5" NODE_VERSION: "18.15.0" TINA_CLIENT_ID: ${{ vars.TINA_CLIENT_ID }} TINA_TOKEN: ${{ vars.TINA_TOKEN }} @@ -49,6 +49,9 @@ jobs: rm go${{ env.GO_VERSION }}.linux-amd64.tar.gz go version + - name: Setup Project + run: npm run project-setup + - name: Install npm dependencies run: npm install @@ -58,7 +61,7 @@ jobs: - name: Upload artifact uses: actions/upload-pages-artifact@v1 with: - path: ./exampleSite/public + path: ./public # Deployment job deploy: diff --git a/exampleSite/.gitlab-ci.yml b/.gitlab-ci.yml similarity index 80% rename from exampleSite/.gitlab-ci.yml rename to .gitlab-ci.yml index fa5e96a..56041e8 100644 --- a/exampleSite/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,9 +3,9 @@ stages: variables: HUGO_ENV: production - HUGO_VERSION: "0.114.0" - GO_VERSION: "1.16.3" - NODE_VERSION: "18.15.0" + HUGO_VERSION: "0.115.1" + GO_VERSION: "1.20.5" + NODE_VERSION: "18.16.1" cache: paths: @@ -28,20 +28,12 @@ default: - echo "GO ${GO_VERSION} INSTALLED" - npm install -test: - stage: build - script: - - npm run build - rules: - - if: $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH - pages: stage: build script: + - npm run project-setup - npm run build - echo "SITE BUILT SUCCESSFULLY! LIVE AT https://$GITLAB_USER_LOGIN.gitlab.io/$CI_PROJECT_NAME/" artifacts: paths: - public - rules: - - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH diff --git a/exampleSite/.editorconfig b/exampleSite/.editorconfig deleted file mode 100755 index 0a6cf5e..0000000 --- a/exampleSite/.editorconfig +++ /dev/null @@ -1,14 +0,0 @@ -; https://editorconfig.org - -root = true - -[*] -charset = utf-8 -end_of_line = lf -indent_size = 2 -indent_style = space -trim_trailing_whitespace = true -insert_final_newline = true - -[*.md] -trim_trailing_whitespace = false diff --git a/exampleSite/.gitignore b/exampleSite/.gitignore deleted file mode 100755 index 5de22b3..0000000 --- a/exampleSite/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -Thumbs.db -.DS_Store -.dist -.tmp -.sass-cache -npm-debug.log -node_modules -builds -package-lock.json -public -resources -.hugo_build.lock -jsconfig.json -hugo_stats.json -go.sum \ No newline at end of file diff --git a/exampleSite/.jshintrc b/exampleSite/.jshintrc deleted file mode 100644 index 873eef9..0000000 --- a/exampleSite/.jshintrc +++ /dev/null @@ -1,59 +0,0 @@ -{ - "maxerr": 50, - "bitwise": true, - "camelcase": false, - "curly": true, - "eqeqeq": true, - "forin": true, - "freeze": true, - "immed": true, - "indent": 2, - "latedef": true, - "newcap": false, - "noarg": true, - "noempty": true, - "nonbsp": true, - "nonew": true, - "plusplus": false, - "undef": true, - "unused": false, - "strict": true, - "maxparams": false, - "maxdepth": 4, - "maxstatements": false, - "maxcomplexity": false, - "maxlen": 400, - "browser": true, - "devel": true, - "asi": false, - "boss": false, - "debug": false, - "eqnull": false, - "es3": false, - "es5": false, - "esversion": 12, - "moz": false, - "evil": true, - "expr": true, - "funcscope": false, - "globalstrict": false, - "iterator": false, - "lastsemic": false, - "laxbreak": false, - "laxcomma": false, - "loopfunc": true, - "multistr": true, - "noyield": false, - "notypeof": false, - "proto": false, - "scripturl": false, - "shadow": false, - "sub": false, - "supernew": false, - "validthis": false, - "globals": { - "jQuery": false, - "google": false, - "$": false - } -} diff --git a/exampleSite/.prettierrc b/exampleSite/.prettierrc deleted file mode 100755 index f222a15..0000000 --- a/exampleSite/.prettierrc +++ /dev/null @@ -1,12 +0,0 @@ -{ - "overrides": [ - { - "files": ["*.html"], - "options": { - "parser": "go-template", - "goTemplateBracketSpacing": true, - "bracketSameLine": true - } - } - ] -} diff --git a/exampleSite/config/_default/config.toml b/exampleSite/config/_default/config.toml index 97f66a3..4a0eccc 100755 --- a/exampleSite/config/_default/config.toml +++ b/exampleSite/config/_default/config.toml @@ -13,12 +13,13 @@ googleAnalytics = "" # example: UA-123-45, for more info, read the article https # disqus short name disqusShortname = "themefisher-template" # we use disqus to show comments in blog posts . To install disqus please follow this tutorial https://portfolio.peter-baumgartner.net/2017/09/10/how-to-install-disqus-on-hugo/ # disable language -disableLanguages = [] # example: ["fr"] for disable french language. see https://gohugo.io/content-management/multilingual/ +disableLanguages = [ +] # example: ["fr"] for disable french language. see https://gohugo.io/content-management/multilingual/ hasCJKLanguage = false # If hasCJKLanguage true, auto-detect Chinese/Japanese/Korean Languages in the content. see: https://gohugo.io/getting-started/configuration/#hascjklanguage ########################## Permalinks ############################ -[permalinks] +[permalinks.page] "pages" = "/:slugorfilename/" diff --git a/exampleSite/netlify.toml b/exampleSite/netlify.toml deleted file mode 100755 index 31c881f..0000000 --- a/exampleSite/netlify.toml +++ /dev/null @@ -1,17 +0,0 @@ -[build] -publish = "public" -command = "yarn build" - -[build.environment] -HUGO_VERSION = "0.112.5" -GO_VERSION = "1.19.4" -HUGO_BASEURL = "/" - -[[headers]] -for = "/*" # This defines which paths this specific [[headers]] block will cover. - -[headers.values] -X-Frame-Options = "DENY" -X-XSS-Protection = "1; mode=block" -Referrer-Policy = "same-origin" -Strict-Transport-Security = "max-age=31536000; includeSubDomains; preload" diff --git a/exampleSite/package.json b/exampleSite/package.json deleted file mode 100644 index 9a0ffbc..0000000 --- a/exampleSite/package.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "hugoplate", - "description": "hugo tailwindcss boilerplate", - "version": "1.1.1", - "license": "MIT", - "author": "zeon.studio", - "scripts": { - "dev": "cd exampleSite; hugo server || hugo server --themesDir ../..", - "test": "cd exampleSite; hugo server --disableFastRender --navigateToChanged --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --watch --forceSyncStatic -e production --minify || hugo server --themesDir ../.. --disableFastRender --navigateToChanged --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --watch --forceSyncStatic -e production --minify", - "build": "cd exampleSite; hugo --gc --minify --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --forceSyncStatic || hugo --themesDir ../.. --gc --minify --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --forceSyncStatic", - "update-modules": "node ./scripts/cleanMod.js && hugo mod clean --all && hugo mod get -u ./... && hugo mod tidy", - "format": "prettier -w .", - "remove-darkmode": "node ./scripts/removeDarkmode.js && yarn format" - }, - "devDependencies": { - "@fullhuman/postcss-purgecss": "^5.0.0", - "@tailwindcss/forms": "^0.5.3", - "@tailwindcss/typography": "^0.5.9", - "autoprefixer": "^10.4.14", - "postcss": "^8.4.24", - "postcss-cli": "^10.1.0", - "prettier": "^2.8.8", - "prettier-plugin-go-template": "0.0.13", - "prettier-plugin-tailwindcss": "^0.3.0", - "tailwind-bootstrap-grid": "^5.0.1", - "tailwindcss": "^3.3.2", - "toml": "^3.0.0" - } -} diff --git a/exampleSite/scripts/removeDarkmode.js b/exampleSite/scripts/removeDarkmode.js deleted file mode 100644 index 9d4b52f..0000000 --- a/exampleSite/scripts/removeDarkmode.js +++ /dev/null @@ -1,52 +0,0 @@ -const fs = require("fs"); -const path = require("path"); - -const rootDirs = [ - "themes/iot-hub-docs/assets/scss", - "themes/iot-hub-docs/layouts", -]; -const configFiles = [ - { - filePath: "tailwind.config.js", - patterns: ["darkmode:\\s*{[^}]*},", 'darkMode:\\s*"class",'], - }, - { - filePath: "config.toml", - patterns: ["\\S*\\.darkmode[^\\]]*\\]\\n*([\\s\\S]*?)(?=\\[|$)"], - }, -]; - -rootDirs.forEach(removeDarkModeFromPages); -configFiles.forEach(removeDarkMode); - -function removeDarkModeFromFiles(filePath, regexPatterns) { - const fileContent = fs.readFileSync(filePath, "utf8"); - let updatedContent = fileContent; - regexPatterns.forEach((pattern) => { - const regex = new RegExp(pattern, "g"); - updatedContent = updatedContent.replace(regex, ""); - }); - fs.writeFileSync(filePath, updatedContent, "utf8"); -} - -function removeDarkModeFromPages(directoryPath) { - const files = fs.readdirSync(directoryPath); - - files.forEach((file) => { - const filePath = path.join(directoryPath, file); - const stats = fs.statSync(filePath); - if (stats.isDirectory()) { - removeDarkModeFromPages(filePath); - } else if (stats.isFile()) { - removeDarkModeFromFiles(filePath, [ - '(?:(?!["])\\S)*dark:(?:(?![,;"])\\S)*', - "@apply?(\\s)*;", - ]); - } - }); -} - -function removeDarkMode(configFile) { - const { filePath, patterns } = configFile; - removeDarkModeFromFiles(filePath, patterns); -} diff --git a/exampleSite/vercel-build.sh b/exampleSite/vercel-build.sh deleted file mode 100755 index 0c101ce..0000000 --- a/exampleSite/vercel-build.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# default versions -if [ -z $GO_VERSION ]; then GO_VERSION='1.19.3'; fi -if [ -z $HUGO_VERSION ]; then HUGO_VERSION='0.112.5'; fi - -# install Go -curl -sSOL https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz -tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz -export PATH=$PATH:/usr/local/go/bin - -# install Hugo -echo "Installing Hugo $HUGO_VERSION..." -curl -sSOL https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz -tar -xzf hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz -hugo version - -# run Hugo -echo "Running Hugo..." -hugo --gc --minify \ No newline at end of file diff --git a/netlify.toml b/netlify.toml index 43d8c62..c5bc70b 100755 --- a/netlify.toml +++ b/netlify.toml @@ -1,18 +1,8 @@ [build] -publish = "exampleSite/public" -command = "yarn build" +publish = "public" +command = "yarn project-setup && yarn build" [build.environment] -HUGO_VERSION = "0.112.5" -GO_VERSION = "1.19.4" -HUGO_THEME = "repo" +HUGO_VERSION = "0.115.1" +GO_VERSION = "1.20.5" HUGO_BASEURL = "/" - -# [[headers]] -# for = "/*" # This defines which paths this specific [[headers]] block will cover. - -# [headers.values] -# X-Frame-Options = "DENY" -# X-XSS-Protection = "1; mode=block" -# Referrer-Policy = "same-origin" -# Strict-Transport-Security = "max-age=31536000; includeSubDomains; preload" diff --git a/package.json b/package.json index 1b677f2..11590f0 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,21 @@ { "name": "hugoplate", "description": "hugo tailwindcss boilerplate", - "version": "1.1.2", + "version": "1.2.0", "license": "MIT", "author": "zeon.studio", "scripts": { - "dev": "cd exampleSite; hugo server || hugo server --themesDir ../..", - "test": "cd exampleSite; hugo server --disableFastRender --navigateToChanged --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --watch --forceSyncStatic -e production --minify || hugo server --themesDir ../.. --disableFastRender --navigateToChanged --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --watch --forceSyncStatic -e production --minify", - "build": "cd exampleSite; hugo --gc --minify --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --forceSyncStatic || hugo --themesDir ../.. --gc --minify --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --forceSyncStatic", - "update-modules": "node ./scripts/cleanMod.js && hugo mod clean --all && hugo mod get -u ./... && hugo mod tidy", - "format": "prettier -w .", - "remove-darkmode": "node ./scripts/removeDarkmode.js && yarn format" + "dev": "hugo server", + "build": "hugo --gc --minify --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --forceSyncStatic", + "test": "hugo server --disableFastRender --navigateToChanged --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --watch --forceSyncStatic -e production --minify", + "dev:example": "cd exampleSite; hugo server --themesDir ../..", + "build:example": "cd exampleSite; hugo --themesDir ../.. --gc --minify --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --forceSyncStatic", + "test:example": "cd exampleSite; hugo server --themesDir ../.. --disableFastRender --navigateToChanged --templateMetrics --templateMetricsHints --buildDrafts --buildExpired --buildFuture --watch --forceSyncStatic -e production --minify", + "update-modules": "node ./scripts/clearModules.js && hugo mod clean --all && hugo mod get -u ./... && hugo mod tidy", + "remove-darkmode": "node ./scripts/removeDarkmode.js && yarn format", + "project-setup": "node ./scripts/projectSetup.js", + "theme-setup": "node ./scripts/themeSetup.js", + "format": "prettier -w ." }, "devDependencies": { "@fullhuman/postcss-purgecss": "^5.0.0", diff --git a/readme.md b/readme.md index 3e0e5eb..dab68e7 100755 --- a/readme.md +++ b/readme.md @@ -63,6 +63,12 @@ - Npm v9.5+ - Tailwindcss v3+ +### 👉 Project Setup + +``` +npm run project-setup +``` + ### 👉 Development Command ``` diff --git a/scripts/cleanMod.js b/scripts/clearModules.js similarity index 75% rename from scripts/cleanMod.js rename to scripts/clearModules.js index 205ed9c..1b9c74a 100644 --- a/scripts/cleanMod.js +++ b/scripts/clearModules.js @@ -1,6 +1,6 @@ const fs = require("fs"); -const clearMode = (filePath) => { +const clearModules = (filePath) => { if (fs.existsSync(filePath)) { let fileContent = fs.readFileSync(filePath, "utf8"); fileContent = fileContent.replace(/require\s*\([\s\S]*?\)/, ""); @@ -10,5 +10,5 @@ const clearMode = (filePath) => { } }; -clearMode("go.mod"); -clearMode("exampleSite/go.mod"); +clearModules("go.mod"); +clearModules("exampleSite/go.mod"); diff --git a/scripts/projectSetup.js b/scripts/projectSetup.js new file mode 100644 index 0000000..a0f4356 --- /dev/null +++ b/scripts/projectSetup.js @@ -0,0 +1,77 @@ +const fs = require("fs"); +const path = require("path"); + +const getFolderName = (rootfolder) => { + const configPath = path.join( + rootfolder, + "exampleSite/config/_default/config.toml" + ); + const getConfig = fs.readFileSync(configPath, "utf8"); + const match = getConfig.match(/theme\s*=\s*\[?"([^"\]]+)"\]?/); + let selectedTheme = null; + if (match && match[1]) { + selectedTheme = match[1]; + } + return selectedTheme; +}; + +const deleteFolder = (folderPath) => { + if (fs.existsSync(folderPath)) { + fs.rmSync(folderPath, { recursive: true, force: true }); + } +}; + +const createNewfolder = (rootfolder, folderName) => { + const newFolder = path.join(rootfolder, folderName); + fs.mkdirSync(newFolder, { recursive: true }); + return newFolder; +}; + +const iterateFilesAndFolders = (rootFolder, { destinationRoot }) => { + const directory = path.join(rootFolder); + const items = fs.readdirSync(directory, { withFileTypes: true }); + items.forEach((item) => { + if (item.isDirectory()) { + createNewfolder(destinationRoot, item.name); + iterateFilesAndFolders(path.join(directory, item.name), { + currentFolder: item.name, + destinationRoot: path.join(destinationRoot, item.name), + }); + } else { + const sourceFile = path.join(directory, item.name); + const destinationFile = path.join(destinationRoot, item.name); + fs.renameSync(sourceFile, destinationFile); + } + }); +}; + +const setupProject = () => { + const rootfolder = path.join(__dirname, "../"); + if (!fs.existsSync(path.join(rootfolder, "themes"))) { + const folderList = ["layouts", "assets", "static"]; + 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); + if (fs.existsSync(source)) { + fs.mkdirSync(destination, { recursive: true }); + iterateFilesAndFolders(source, { + currentFolder: folder, + destinationRoot: destination, + }); + deleteFolder(source); + } + }); + + const exampleSite = path.join(rootfolder, "exampleSite"); + iterateFilesAndFolders(exampleSite, { destinationRoot: rootfolder }); + deleteFolder(exampleSite); + } +}; + +setupProject(); diff --git a/scripts/themeSetup.js b/scripts/themeSetup.js new file mode 100644 index 0000000..2b772e4 --- /dev/null +++ b/scripts/themeSetup.js @@ -0,0 +1,93 @@ +const fs = require("fs"); +const path = require("path"); + +const createNewfolder = (rootfolder, folderName) => { + const newFolder = path.join(rootfolder, folderName); + fs.mkdirSync(newFolder, { recursive: true }); + return newFolder; +}; + +const deleteFolder = (folderPath) => { + if (fs.existsSync(folderPath)) { + fs.rmSync(folderPath, { recursive: true, force: true }); + } +}; + +const getFolderName = (rootfolder) => { + const configPath = path.join( + rootfolder, + "exampleSite/config/_default/config.toml" + ); + const getConfig = fs.readFileSync(configPath, "utf8"); + const match = getConfig.match(/theme\s*=\s*\[?"([^"\]]+)"\]?/); + let selectedTheme = null; + if (match && match[1]) { + selectedTheme = match[1]; + } + return selectedTheme; +}; + +const iterateFilesAndFolders = (rootFolder, { destinationRoot }) => { + const directory = path.join(rootFolder); + const items = fs.readdirSync(directory, { withFileTypes: true }); + items.forEach((item) => { + if (item.isDirectory()) { + createNewfolder(destinationRoot, item.name); + iterateFilesAndFolders(path.join(directory, item.name), { + currentFolder: item.name, + destinationRoot: path.join(destinationRoot, item.name), + }); + } else { + const sourceFile = path.join(directory, item.name); + const destinationFile = path.join(destinationRoot, item.name); + fs.renameSync(sourceFile, destinationFile); + } + }); +}; + +const setupTheme = () => { + const rootFolder = path.join(__dirname, "../"); + + if (!fs.existsSync(path.join(rootFolder, "exampleSite"))) { + const includesFiles = [ + "tailwind.config.js", + "postcss.config.js", + "go.mod", + "config.toml", + "assets", + "config", + "content", + "i18n", + "static", + ]; + + const folder = createNewfolder(rootFolder, "exampleSite"); + console.log({ folder }); + + fs.readdirSync(rootFolder, { withFileTypes: true }).forEach((file) => { + if (includesFiles.includes(file.name)) { + if (file.isDirectory()) { + const destination = path.join(rootFolder, "exampleSite", file.name); + fs.mkdirSync(destination, { recursive: true }); + iterateFilesAndFolders(path.join(rootFolder, file.name), { + destinationRoot: destination, + }); + deleteFolder(path.join(rootFolder, file.name)); + } else { + fs.renameSync( + path.join(rootFolder, file.name), + path.join(folder, file.name) + ); + } + } + }); + + const themes = path.join(rootFolder, "themes"); + iterateFilesAndFolders(path.join(themes, getFolderName(rootFolder)), { + destinationRoot: rootFolder, + }); + deleteFolder(themes); + } +}; + +setupTheme(); diff --git a/vercel-build.sh b/vercel-build.sh new file mode 100755 index 0000000..c9c4055 --- /dev/null +++ b/vercel-build.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# default versions +NODE_VERSION='18.16.1'; +GO_VERSION='1.20.5'; +HUGO_VERSION='0.115.1'; + +# install Node.js +# echo "Installing Node.js $NODE_VERSION..." +# curl -sSOL https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}.tar.gz +# tar -xzf node-v${NODE_VERSION}.tar.gz +# export PATH=$PATH:/usr/local/bin +# rm -rf node-v${NODE_VERSION}.tar.gz + +echo "USING NODE VERSION: $(node -v)" + +# install Go +echo "Installing Go $GO_VERSION..." +curl -sSOL https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz +tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz +export PATH=$PATH:/usr/local/go/bin +rm -rf go${GO_VERSION}.linux-amd64.tar.gz +go version + +# install Hugo +echo "Installing Hugo $HUGO_VERSION..." +curl -sSOL https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz +tar -xzf hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz +mv hugo /usr/local/bin/ +rm -rf hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz +hugo version + +# project setup +echo "Project setting up..." +npm run project-setup + +# install dependencies +echo "Installing project dependencies..." +npm install + +# run the build command +echo "Running the build command..." +npm run build diff --git a/exampleSite/vercel.json b/vercel.json similarity index 100% rename from exampleSite/vercel.json rename to vercel.json