diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 08f2878..c5c472c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -26,28 +26,6 @@ jobs: ENCODE_PROFILE_DATA=$(node -pe "require('./src/config/config.json').encodeProfileData") echo "ENCODE_PROFILE_DATA=$ENCODE_PROFILE_DATA" >> $GITHUB_ENV - - name: Prepare profile data (encodeProfileData= true) - if: env.ENCODE_PROFILE_DATA == 'true' - run: | - if [ -f public/data/b64ProfileData.json ]; then - echo "b64ProfileData.json already exists." - else - if [ -f src/data/profileData.json ]; then - npm run prebuild - else - cp src/data/profileData.template.json src/data/profileData.json - npm run prebuild - fi - fi - - - name: Prepare profile data (encodeProfileData= false) - if: env.ENCODE_PROFILE_DATA == 'false' - run: | - if [ ! -f src/data/profileData.json ]; then - cp src/data/profileData.template.json src/data/profileData.json - npm run prebuild - fi - - name: Build project run: | PUBLIC_URL="https://$(echo $GITHUB_REPOSITORY | awk -F / '{print tolower($1)}').github.io/$(echo $GITHUB_REPOSITORY | awk -F / '{print tolower($2)}')" npm run build diff --git a/README.md b/README.md index 8e9ac90..423d058 100644 --- a/README.md +++ b/README.md @@ -108,8 +108,8 @@ Feel free to fork this project and make it your own. Here's how to deploy your v 2. Customize images to avoid using the default ones, such as my dog's photo. 3. Prepare your data for deployment with `npm run prebuild`. 4. Commit the base64 encoded data file. -5. Deploy to your preferred service, like GitHub Pages (Works out of the box). - +5. Deploy to your preferred service, like GitHub Pages (Works out of the box, just enable Actions and give them the correct permissions: Actions -> General -> Workflow -> Read and write permissions ). +6. Enable GH Pages -> Pages -> "Deploy from a branch" -> "gh-pages" Happy sharing of your professional digital business card! ## Screenshots diff --git a/prebuild.js b/prebuild.js index 9a3d483..486913d 100644 --- a/prebuild.js +++ b/prebuild.js @@ -4,28 +4,41 @@ const config = require('./src/config/config.json'); if (config.encodeProfileData) { const profileDataPath = path.join(__dirname, 'src', 'data', 'profileData.json'); + const profileTemplatePath = path.join(__dirname, 'src', 'data', 'profileData.template.json'); const encodedDataPath = path.join(__dirname, 'public', 'data', 'b64ProfileData.json'); - // Check if profileData.json exists - if (fs.existsSync(profileDataPath)) { - const profileDataStat = fs.statSync(profileDataPath); - let shouldEncode = true; + let shouldEncode = true; - // Check if b64ProfileData.json exists - if (fs.existsSync(encodedDataPath)) { - const encodedDataStat = fs.statSync(encodedDataPath); - // Compare modification times - shouldEncode = profileDataStat.mtime > encodedDataStat.mtime; + // Check if profileData.json exists, if not create it from template + if (!fs.existsSync(profileDataPath)) { + if (fs.existsSync(profileTemplatePath)) { + fs.copyFileSync(profileTemplatePath, profileDataPath); + console.log("No profileData.json existing, generating a new one, please fill out your personal information here, or ignore this log, if your b64ProfileData.json is up to date."); + shouldEncode = false; // The newly created file will be identical to the template + } else { + console.log("profileData.template.json is missing, unable to create profileData.json."); + return; } + } else if (fs.existsSync(encodedDataPath)) { + const profileDataStat = fs.statSync(profileDataPath); + const encodedDataStat = fs.statSync(encodedDataPath); - if (shouldEncode) { - const profileData = fs.readFileSync(profileDataPath, 'utf8'); - const encodedData = Buffer.from(profileData).toString('base64'); - fs.writeFileSync(encodedDataPath, encodedData); - } else { - console.log("It seems like you always have a newer b64 encoded profileData.json, to overwrite pls update src/data/profileData.json or remove the generated public/data/b64ProfileData.json") + // Compare modification times + shouldEncode = profileDataStat.mtime > encodedDataStat.mtime; + + // Check if the content of profileData.json is identical to the template + const profileDataContent = fs.readFileSync(profileDataPath, 'utf8'); + const templateContent = fs.readFileSync(profileTemplatePath, 'utf8'); + if (profileDataContent === templateContent) { + shouldEncode = false; } + } + + if (shouldEncode) { + const profileData = fs.readFileSync(profileDataPath, 'utf8'); + const encodedData = Buffer.from(profileData).toString('base64'); + fs.writeFileSync(encodedDataPath, encodedData); } else { - console.log("It seems like you don't have a src/data/profileData.json yet, copy the profileData.template.json file, rename it to profileData.json, fill out your information and run npm run prebuild."); + console.log("The profile data is up to date and does not need to be encoded."); } }