-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
111 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,5 @@ pnpm-lock.yaml | |
|
||
|
||
#cached openai responses | ||
.aicache/ | ||
.aicache/ | ||
.vercel/output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"siteTitleSuffix": " - img.style", | ||
"siteTitleName": "image styling & optimization", | ||
"skipToContentText": "Skip to Content", | ||
"editPage": "Edit this page", | ||
"joinCommunity": "Join our community", | ||
"footerLicense": "This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License", | ||
"translatedContentDisclaimer": "Please let us know if something isn't right. Our translator isn't quite sentient yet, but does incorporate feedback, so please leave some tips!", | ||
"reportIssue": "Get in touch on Github", | ||
"sidebarTitle": "Topics", | ||
"communitySidebarTitle": "Community" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { SITE } from "../src/consts"; | ||
|
||
// print info | ||
|
||
console.log("SITE", SITE); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { switchSite } from "./switch_sites"; | ||
import { CONTENT_COLLECTIONS } from "../src/consts"; | ||
|
||
const site = process.argv[2]; | ||
if (!site) { | ||
console.error("Please specify site key such as 'srcset' or 'imgstyle'. Ex. npm run switch -- srcset OR npm run switch -- imgstyle"); | ||
}else{ | ||
switchSite(site); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { SITES_KEYS } from "../src/consts"; | ||
|
||
async function searchFilenamesRecursive(directory: string, include: string): Promise<string[]> { | ||
const entries = await fs.promises.readdir(directory, { withFileTypes: true }); | ||
const files: string[] = []; | ||
|
||
for (const entry of entries) { | ||
const fullPath = path.join(directory, entry.name); | ||
if (entry.isDirectory()) { | ||
const subDirectoryFiles = await searchFilenamesRecursive(fullPath, include); | ||
files.push(...subDirectoryFiles); | ||
} else if (entry.isFile() && entry.name.includes(include)) { | ||
files.push(fullPath); | ||
} | ||
} | ||
return files; | ||
} | ||
|
||
async function switchSymlinks(directory: string, newSitekey: string) { | ||
const searchPart = `.${newSitekey}.`; | ||
const files = await searchFilenamesRecursive(directory, searchPart); | ||
for (const newFile of files) { | ||
const defaultFile = newFile.replace(searchPart, '.'); | ||
// Check if defaultFile is a symlink | ||
const stats = await fs.promises.lstat(defaultFile); | ||
if (stats.isSymbolicLink()) { | ||
// print what it points to | ||
const link = await fs.promises.readlink(defaultFile); | ||
// if link is already newFile, skip | ||
if (link === newFile) { | ||
console.log('Link already exists from ' + defaultFile + " to " + link); | ||
continue; | ||
} | ||
console.log('Unlinking ' + defaultFile + ' from using ' + link); | ||
// delete symlink | ||
await fs.promises.unlink(defaultFile); | ||
// symlink defaultFile to newFile | ||
console.log('Linking ' + defaultFile + ' to use ' + newFile); | ||
await fs.promises.symlink(newFile, defaultFile); | ||
} else { | ||
console.log('!!!! Error, not a symlink: ' + defaultFile); | ||
|
||
console.log('Not a symlink'); | ||
} | ||
} | ||
} | ||
export async function switchSite(siteKey: string) { | ||
// check siteKey is valid | ||
if (!SITES_KEYS.includes(siteKey)) { | ||
console.log('Error: invalid site key (' + siteKey + ')'); | ||
return; | ||
} | ||
|
||
console.log('Switching active site to ' + siteKey); | ||
|
||
// check the current folder contains 'astro.config.mjs', if not fail | ||
const astroConfigPath = path.join(process.cwd(), 'astro.config.mjs'); | ||
if (!fs.existsSync(astroConfigPath)) { | ||
console.log('Error: astro.config.mjs not found in current directory. Run this from root'); | ||
return; | ||
} | ||
|
||
await switchSymlinks(process.cwd(), siteKey); | ||
} |