Skip to content

Commit

Permalink
Static image symlink, instead of preprocessing step
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed Sep 9, 2021
1 parent 6b542a1 commit 73a1aae
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 41 deletions.
41 changes: 0 additions & 41 deletions src/build/preprocess.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ function fixMdOnEvent(eventType, path, partitioner, verbose, simulate) {

function doPrePartitioning(config, clear, simulate, verbose) {
setupBuildDirs(config.buildDirs, clear, simulate, verbose);
linkStaticImages(config.projectRoot, config.contentDir, simulate, verbose);
}

function setupBuildDirs(buildDirs, clear, simulate, verbose) {
Expand All @@ -214,43 +213,3 @@ function setupBuildDirs(buildDirs, clear, simulate, verbose) {
}
}
}

function linkStaticImages(projectRoot, contentDir, simulate, verbose) {
let linkPath = nodePath.join(projectRoot, "static/images");
let targetPath = nodePath.join(contentDir, "images");
let relativePath = nodePath.relative(nodePath.dirname(linkPath), targetPath);
let linkInfo = new PathInfo(linkPath);
if (linkInfo.exists()) {
if (linkInfo.isLink()) {
let existingRelativePath = fs.readlinkSync(linkPath);
if (relativePath === existingRelativePath) {
if (verbose) {
console.log(repr`Static images link already exists.`);
}
return;
} else {
console.log(repr`Static images link already exists but is wrong: ${existingRelativePath}`);
if (!simulate) {
fs.unlinkSync(linkPath);
}
}
} else {
throw repr`Path already exists but is not a symlink: ${linkPath}`;
}
}
let linkDir = nodePath.dirname(linkPath);
if (!PathInfo.exists(linkDir)) {
if (verbose) {
console.log(repr`Creating ${linkDir}..`);
}
if (!simulate) {
fs.mkdirSync(linkDir, { recursive: true });
}
}
if (verbose) {
console.log(repr`Linking to ${relativePath} from ${linkPath}..`);
}
if (!simulate) {
fs.symlinkSync(relativePath, linkPath);
}
}
1 change: 1 addition & 0 deletions static/images

0 comments on commit 73a1aae

Please sign in to comment.