Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request for comments]: Site Versioning #1870

Draft
wants to merge 38 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4eb63a8
Working Archive + deploy command
kaixin-hc Apr 2, 2022
e180361
Fix archived site links + streamline functions
kaixin-hc Apr 2, 2022
c229160
Fix URL bug
kaixin-hc Apr 4, 2022
e64f91c
clean up comments in cli file
kaixin-hc Apr 9, 2022
778f3cb
Exclude archived site from being archived with markbind archive
kaixin-hc Apr 9, 2022
95298d4
Add documentation for the CLI command
kaixin-hc Apr 9, 2022
8eed90c
Docs: Write Versioning Documentation
kaixin-hc Apr 9, 2022
8453f7a
Fix Error logging
kaixin-hc Apr 9, 2022
1ba8c91
Revert changes to deploy
kaixin-hc Apr 16, 2022
f113c22
Make changes according to Yongliang's suggestions
kaixin-hc Apr 16, 2022
0769bc7
Merge in master branch changes
kaixin-hc Apr 16, 2022
aca406b
Correctly ignore subsites versions
kaixin-hc Apr 18, 2022
7f559b1
Merge master branch changes in
kaixin-hc Apr 18, 2022
792c156
Amend spacing in cliCommands
kaixin-hc Apr 18, 2022
4fc9090
Merge branch 'master' into site-versioning
kaixin-hc Apr 18, 2022
798d63f
Fix error made when merging
kaixin-hc Apr 18, 2022
b85641a
Working to copy over files for serve
kaixin-hc Apr 21, 2022
9beec61
Change versions.json formatting
kaixin-hc Apr 21, 2022
ad5f0ff
Correctly deploy selected versions
kaixin-hc Apr 21, 2022
601d343
Add documentation about versioning
kaixin-hc Apr 21, 2022
b52a341
Correctly exclude site whose baseUrls do not match
kaixin-hc Apr 21, 2022
039c0bd
Update versioning example and add additional warning
kaixin-hc Apr 21, 2022
f394060
correct typo
kaixin-hc Apr 21, 2022
c77b95e
Fix some comments
kaixin-hc May 2, 2022
5f8e427
Merge in master
kaixin-hc Jun 9, 2022
2362390
Change behaviour of --version flag & set archivePath flag + nits
kaixin-hc Jun 15, 2022
3337749
Merge branch 'master' into site-versioning
kaixin-hc Jun 20, 2022
46632f1
Refactor copying of versions & versions information, fix bug
kaixin-hc Jun 20, 2022
5ef1776
Add read from versions file
kaixin-hc Jun 20, 2022
850aa18
Add write version file tests + fix bugs + warning message
kaixin-hc Jun 21, 2022
d6cc776
Add testcases for copying selected versions
kaixin-hc Jun 22, 2022
a4505ce
Delete superfluous test
kaixin-hc Jun 22, 2022
f8ee5d7
Add missing test files due to versioning
kaixin-hc Jun 22, 2022
1bdb924
Add ignore site tests + fix bug
kaixin-hc Jun 22, 2022
3745f7a
Fixing paths for windows
kaixin-hc Jun 22, 2022
d89e2a6
Chore: fix bug?
kaixin-hc Jun 22, 2022
7d8125d
Update documentation
kaixin-hc Jun 23, 2022
14fe6ec
Chore: Documentation changes
kaixin-hc Jun 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/_markbind/layouts/userGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* [Making the Site Searchable]({{baseUrl}}/userGuide/makingTheSiteSearchable.html)
* [Applying Themes]({{baseUrl}}/userGuide/themes.html)
* [Deploying the Site]({{baseUrl}}/userGuide/deployingTheSite.html)
* [Versioning]({{baseUrl}}/userGuide/versioning.html)
* [MarkBind in the Project Workflow]({{baseUrl}}/userGuide/markBindInTheProjectWorkflow.html)
* **References** :expanded:
* [CLI Commands]({{baseUrl}}/userGuide/cliCommands.html)
Expand Down
42 changes: 42 additions & 0 deletions docs/userGuide/cliCommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,48 @@ The caveat is that not building all pages during the initial process, or not reb

<hr><!-- ========================================================================== -->

### `archive` Command
kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved
<br>

**Format:** `markbind archive [options] [versionName] [archivePath]`

**Alias:** `markbind ar`

**Description:** Archives a version of the current site, which will not be affected by future changes to the site

kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved
**Arguments:**

<div id="archiveWarning">
<box type="warning">

Warning: If the folder at `<archivePath>/<versionName>` already exists, the contents will be overwritten and your previous files may be lost. Only do so if you need to replace all the archived files with the current site files.
kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved
</box>
</div>

* `[versionName]`<br>
The name of the version, and the folder which the generated HTML files and assets will be stored in.<br>
kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved
{{ icon_example }} `version_1`
tlylt marked this conversation as resolved.
Show resolved Hide resolved

* `[archivePath]`<br>
All archived versions are stored in the folder `<archivePath>/<versionName>`. The default archivePath is `version` <br>
{{ icon_example }} `custom_archive_path`

<panel header="**Options** :fas-cogs:" type="minimal" expanded>

**Options** :fas-cogs:

* `-s <file>`, `--site-config <file>`<br>
Specify the site config file (default: `site.json`)<br>
{{ icon_example }} `-s otherSite.json`

**{{ icon_examples }}**
* `markbind archive v1` - Stores the site in the directory `version/v1` (from the root)
* `markbind archive version_1 custom_archive_path` - Stores the site in the directory `custom_archive_path/version_1` (from the root)
kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved

</panel>

<hr><!-- ========================================================================== -->

### `deploy` Command
<br>

Expand Down
2 changes: 1 addition & 1 deletion docs/userGuide/deployingTheSite.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,4 @@ For more information on Surge, you may refer to [Surge's docs](https://surge.sh/
</panel>

{% from "njk/common.njk" import previous_next %}
{{ previous_next('themes', 'markBindInTheProjectWorkflow') }}
{{ previous_next('themes', 'versioning') }}
2 changes: 1 addition & 1 deletion docs/userGuide/markBindInTheProjectWorkflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ To convert your existing project, follow these steps:
</box>

{% from "njk/common.njk" import previous_next %}
{{ previous_next('deployingTheSite', '') }}
{{ previous_next('versioning', '') }}
32 changes: 32 additions & 0 deletions docs/userGuide/versioning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% set title = "Site Versioning" %}
{% set filename = "versioning" %}
<span id="title" class="d-none">{{ title }}</span>

<frontmatter>
title: "User Guide: {{ title }}"
layout: userGuide.md
</frontmatter>

<span id="link" class="d-none">
<md>[_User Guide → {{ title }}_]({{ filename }}.html)</md>
</span>

# {{ title }}

<div class="lead" id="overview">

Site versioning is key for documentation use, and websites may want to keep past versions for archival purposes. MarkBind can help you easily archive your site.
</div>

kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved
## Archiving with a CLI command

Markbind allows you to easily save a version of the site you've built to be hosted at the same site with a modified URL with a single CLI command. All intralinks within the archived site will point to the respective archived pages. By default, the archive folder is called `version`, but you may specify your own directory.
kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved

For example, if your site's base url relative to your domain is 'my_site', and you archive a version named 'v1' in the default archive folder, then by navigating to the url `<domain>/my_site/version/v1/<someFile>` you would have accessed the archived version of someFile.
kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved

A `versions.json` file will be created to track the archived sites you have made, and to exclude the archived sites from being re-archived the next time you make a new version. Modify it with caution, as it may result in unnecessary files being included or necessary files being excluded.
kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved

<include src="cliCommands.md#archiveWarning">

{% from "njk/common.njk" import previous_next %}
{{ previous_next('deployingTheSite', 'markBindInTheProjectWorkflow') }}
24 changes: 23 additions & 1 deletion packages/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,38 @@ program
.catch(handleError);
});

program
.command('archive [versionName] [archivePath]')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we put archivePath into a named parameter instead? (e.g. -p --archive-path)
Since we don't expect that most people would need to change this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I agree with this! Will do so unless anyone else disagrees.

.alias('ar')
.option('-s, --site-config <file>', 'specify the site config file (default: site.json)')
.description('archive a version of the site, which is not affected by later changes to the site')
.action((versionName, userSpecifiedArchivePath, options) => {
if (!versionName) {
logger.error('Please specify a name for the archived version.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe can throw an error here so that it will stop the archiving process if the version name is not specified?

Currently, it will be archived as undefined:
image

}
const archivePath = userSpecifiedArchivePath || 'version';
const rootFolder = path.resolve(process.cwd());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if we should add in archive [root] <versionName> to make things consistent with the other commands (cliUtil.findRootFolder), but it should be backward compatible in any case so we can decide on this later.

I think minimally we could add in a small note in the cli commands page that the site archived is the cwd's one.

const outputFolder = path.join(rootFolder, archivePath, versionName);
new Site(rootFolder, outputFolder, undefined, undefined, options.siteConfig)
.archive(versionName, archivePath)
.then(() => {
logger.info(`Successfully archived ${versionName} at ${archivePath}/${versionName}`);
})
.catch(handleError);
});

program
.command('deploy')
.alias('d')
.description('deploy the site to the repo\'s Github pages')
.option('-c, --ci [githubTokenName]', 'deploy the site in CI Environment [GITHUB_TOKEN]')
.option('-s, --site-config <file>', 'specify the site config file (default: site.json)')
.option('-v, --versions <versionFolder>', 'specify the path where versions are stored')
kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved
.action((options) => {
const rootFolder = path.resolve(process.cwd());
const outputRoot = path.join(rootFolder, '_site');
new Site(rootFolder, outputRoot, undefined, undefined, options.siteConfig).deploy(options.ci)
const site = new Site(rootFolder, outputRoot, undefined, undefined, options.siteConfig);
site.deploy(options.ci)
kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved
.then(depUrl => (depUrl !== null ? logger.info(
`The website has been deployed at: ${depUrl}`)
: logger.info('Deployed!')))
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/Site/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
PAGE_TEMPLATE_NAME: 'page.njk',
SITE_CONFIG_NAME: 'site.json',
SITE_DATA_NAME: 'siteData.json',
VERSIONS_DATA_NAME: 'versions.json',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
VERSIONS_DATA_NAME: 'versions.json',
VERSIONS_DATA_NAME: '_markbind/versions.json',

should we? in view of all the other stuff in there

LAYOUT_SITE_FOLDER_NAME: 'layouts',
LAZY_LOADING_SITE_FILE_NAME: 'LazyLiveReloadLoadingSite.html',
LAZY_LOADING_BUILD_TIME_RECOMMENDATION_LIMIT: 30000,
Expand Down
115 changes: 104 additions & 11 deletions packages/core/src/Site/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const {
PAGE_TEMPLATE_NAME,
SITE_CONFIG_NAME,
SITE_DATA_NAME,
VERSIONS_DATA_NAME,
SITE_FOLDER_NAME,
TEMP_FOLDER_NAME,
TEMPLATE_SITE_ASSET_FOLDER_NAME,
Expand Down Expand Up @@ -134,6 +135,12 @@ class Site {
this.siteConfig = undefined;
this.siteConfigPath = siteConfigPath;

/**
* Archived version information
* @type {undefined | SiteConfig}
kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved
*/
this.versionData = undefined;

// Site wide variable processor
this.variableProcessor = undefined;

Expand Down Expand Up @@ -652,17 +659,8 @@ class Site {

try {
await this.readSiteConfig(baseUrl);
this.collectAddressablePages();
await this.collectBaseUrl();
this.collectUserDefinedVariablesMap();
await this.buildAssets();
await (this.onePagePath ? this.lazyBuildSourceFiles() : this.buildSourceFiles());
await this.copyCoreWebAsset();
await this.copyBootstrapTheme(false);
await this.copyFontAwesomeAsset();
await this.copyOcticonsAsset();
await this.copyMaterialIconsAsset();
await this.writeSiteData();
await this.buildSiteHelper();
kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved

this.calculateBuildTimeForGenerate(startTime, lazyWebsiteGenerationString);
if (this.backgroundBuildMode) {
this.backgroundBuildNotViewedFiles();
Expand All @@ -672,6 +670,23 @@ class Site {
}
}

/**
* Holds the work for generating a site.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Holds the work for generating a site.
* Holds the work for generating a site completely.

(as opposed to the regeneration ones)

*/
async buildSiteHelper() {
this.collectAddressablePages();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in the way you are thinking, but I realised with your comment you'll also need to add the versioned site folders to the pagesExclude property here.
https://markbind.org/userGuide/siteJsonFile.html#pagesexclude

This is as:

we support building html files as pages as well
.md files may be copied to output folders as an asset in some projects

I think missed this part too (implementation is inside this function)
#1870 (comment)

await this.collectBaseUrl();
this.collectUserDefinedVariablesMap();
await this.buildAssets();
await (this.onePagePath ? this.lazyBuildSourceFiles() : this.buildSourceFiles());
await this.copyCoreWebAsset();
await this.copyBootstrapTheme(false);
await this.copyFontAwesomeAsset();
await this.copyOcticonsAsset();
await this.copyMaterialIconsAsset();
await this.writeSiteData();
}

/**
* Helper function for generate().
*/
Expand Down Expand Up @@ -1467,6 +1482,84 @@ class Site {
}
}

/**
* Archive the current version of the site.
kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved
*
* @param {string} versionName the name of the version
* @param {string} archivePath the path to the folder to store the archives in
*/
async archive(versionName, archivePath) {
await this.readSiteConfig();

// Save version data
const versionPath = `${archivePath}/${versionName}`;
this.versionData = await this.writeVersionsFile(versionName, versionPath);
// Exclude versioned files from archiving.
const archiveFolders = this.versionData.versions;
archiveFolders.forEach((folder) => {
const filePath = `/${folder.output}/**`;
this.siteConfig.ignore.push(filePath);
kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved
});

// Used to get accurate intralinks within the archived site:
const archivedBaseUrl = this.siteConfig.baseUrl === ''
? `/${versionPath}`
: `${this.siteConfig.baseUrl}/${versionPath}`;
this.siteConfig.baseUrl = archivedBaseUrl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks like on the right track, I think the biggest missing thing may be:

copy over the generated version of the website into a sub folder under the _sites folder for subsequent deployment

I realised with this note, perhaps we could also store the baseUrl used to archive the version (if we ever want to support changing baseurls) inside versions.json, as differing baseUrls shouldn't be copied over to _site.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean by "differing baseUrls sholudn't be copied over to _site" - from my understanding, the HTML files do away with references to baseURL by replacing references to baseURL with the baseURL. But yes, I can definitely store the archived site's baseUrl!

Copy link
Contributor

@jonahtanjz jonahtanjz Apr 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean by "differing baseUrls sholudn't be copied over to _site"

I believe for now, if we do a markbind build after the archive command, the archived HTML files will be copied over to the _site folder (which assumes that they have the same baseUrl as the main site). If the archived sites have a different baseUrl, then their HTML files should not be copied over to _site folder since they are probably not going to be part of the same deployment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I see...

It makes sense that differing baseUrls shouldn't be copied over (as they wouldn't be able to be deployed), but I wonder if there are any cases where the baseUrls might differ, but you might still want to include it as part of the same deployment and it would work (something like a root baseUrl being 'root' and the subsite baseUrl being "root/subsite" - it still could be part of the same deployment (?)).

I think copying it over is not a significant cost or a bug, and if the user wants to it is easy to manually exclude by indicating that folder as a folder to ignore. But it shouldn't be too hard to exclude the files as well 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I wonder if there are any cases where the baseUrls might differ, but you might still want to include it as part of the same deployment and it would work (something like a root baseUrl being 'root' and the subsite baseUrl being "root/subsite" - it still could be part of the same deployment (?)).

Subsites are meant to be entire sites able to be deployed independently.

Our support for subsites is more about content reuse https://markbind.org/userGuide/reusingContents.html#reusing-contents-across-sites, in particular revolving around resolving {{baseUrl}} properly

E.g.

Main site, baseUrl is '/cat'
Subsite , baseUrl is '/dog'

subsite index.md

[some link]({{baseUrl}}/foobar)

If you deploy the subsite independently, baseUrl resolves to /dog.

If you deploy the main site, baseUrl resolves to the main site base url + sub folder (i.e. /cat/subfolder/of/subsite).

This is important wherever there are links involved (link validaiton, relative link resolving, <include>s, ...).

by indicating that folder as a folder to ignore.

If I'm getting this part right (ignore as in the ignore property), the versioning system's copying mechanism needs to be independent of asset copying (the ignore property).

e.g. if you have

ignore: ["xx.png"]

but at the point of archiving, xx.png wasn't present (meaning the author did indeed want to copy it over). The copying for versioning should still copy xx.png over.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point on ignore however is this: If you had archived a site, say into versions/v1. Then, you ran markbind build/serve. MarkBind's asset copying would incorrectly / incompletely copy some parts of it over (since it is in the project source folder). This copying mechanism therefore needs to be implemented separately of this. The asset copying should also exclude said archive folders.

Copy link
Contributor Author

@kaixin-hc kaixin-hc Apr 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ang-zeyu Oh :0 So the desired default behaviour, is to serve only the current site, and not any archived sites, because of the cost in copying over large sites? That makes sense. I had assumed the opposite, which is that if the user had archived the site previously they would want to check it when building and serving.

Currently, my understanding/implementation is:

  • When the site is archived, the site is built with a changed baseUrl and placed into a certain folder, the location of which is tracked in versions.json - previously archived versions will not be re-archived.
    • (Currently working on subsite versions not being re-archived, should be done soon)
  • Every time the site is built/served, the contents of _site are wiped clean, and replaced by the newly built files + copied over assets (which now include the versioned sites).
    • To avoid deploying versioned sites, this is currently relying on the user manually specifying to ignore that folder.
    • Asset copying "correctly" moves over all the versioned sites, allowing the user to navigate to past versions in their live preview
  • Every time the site is deployed, the contents of _site and only those contents are transferred to gh-pages branch --> this will include all versioned sites which were not specifically ignored by the user.

And what I understand from your suggestion is that:

  • when archiving, also move the archived site files into a subfolder in _site
  • change the way the site is built and served such that only the current site is built and served, ignoring the new subfolders in _site which hold versions.
    • Hence we can't wipe _site clean, and will need to store the names of subfolders to "ignore"(either not overriding with versioning or not serving with markbind serve)
    • And I assume also adding options to allow the build and serve commands to also show archived sites, if specified.
      (One clarifying question: does this mean you suggest to store the archived site two places, both in _site and in the folder <archivePath>/<versionName> ?)

I can give it a shot, but do you think I can leave this as an improvement for another PR? I think it might be a little tricky because it affects big commands and features and might take more than a few days to implement carefully (might also make reviewing easier)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, nothing so complex, ignore the additional point on markbind serve first, I'll come back to that later.
Your current understanding is mostly already correct.

and replaced by the newly built files + copied over assets (which now include the versioned sites).

Asset copying "correctly" moves over all the versioned sites, allowing the user to navigate to past versions in their live preview

This is the main issue, it is incorrect to rely on asset copying for this. #1870 (comment)

You'll have to implement an independent copying mechanism.

If you need convincing, try archiving our documentation with markbind archive v1. Then, add appveyorAddNewProject.png to ignore, and run markbind build. The image will be missing from the archived site in versions/v1/images.

Copy link
Contributor

@ang-zeyu ang-zeyu Apr 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*Please make sure you get the above comment before reading this comment, otherwise it'll only be more confusing

~in which case (for markbind serve), I think to avoid copying the entire archived site over every file change/add/delete (expensive to copy large site over), we could also aim to do this only once 🤔 (realised its not possible to preview archived sites in markbind serve with #267 not done yet) (might be possible)

Back to this, my concern here was just with this:

  1. author runs markbind serve
  2. your yet-to-implement copying mechanism copies the versioned sites over
  3. author edits files... continues with development
    3.1 Triggers your copying mechanism everytime (file change/addition/deletion). This is rather disk intensive / expensive and might slow the development experience a fair bit.

change the way the site is built and served such that only the current site is built and served, ignoring the new subfolders in _site which hold versions.

Not in the way you are thinking, but I realised with your comment you'll also need to add the versioned site folders to the pagesExclude property here.
https://markbind.org/userGuide/siteJsonFile.html#pagesexclude

This is as:

  • we support building html files as pages as well
  • .md files may be copied to output folders as an asset in some projects

I believe for now, if we do a markbind build after the archive command, the archived HTML files will be copied over to the _site folder (which assumes that they have the same baseUrl as the main site). If the archived sites have a different baseUrl, then their HTML files should not be copied over to _site folder since they are probably not going to be part of the same deployment.

Back to @jonahtanjz's comment here as well, you'll need to take note of this when implementing the copying as well. (i.e. don't copy archived sites with different baseurl from the current one in site.json)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining that again, and for the simple example - that's really useful to test my thoughts.

I hadn't realized that we "supported building html files as pages". I had the understanding that "building" a page was converting it from .md to a generated .html - will take a closer look at this.


// Create the .tmp folder for storing intermediate results.
fs.emptydirSync(this.tempPath);
// Clean the output folder; create it if not exist.
fs.emptydirSync(this.outputPath);

try {
await this.buildSiteHelper();
} catch (error) {
await Site.rejectHandler(error, [this.tempPath, this.outputPath]);
}
}

/**
* If the versions.json file exists, update it with a new version.
* Otherwise, create a new versions file to store information about archived versions
*
* @param {boolean} verbose Flag to emit logs of the operation
* @returns Returns the json object of the current versions data.
*/
async writeVersionsFile(versionName, versionPath, verbose = true) {
const versionsPath = path.join(this.rootPath, VERSIONS_DATA_NAME);
const newVersionData = {
version_name: versionName,
build_ver: MARKBIND_VERSION,
kaixin-hc marked this conversation as resolved.
Show resolved Hide resolved
output: versionPath,
};

try {
if (!fs.pathExistsSync(versionsPath)) {
// Initialize the versions.json file.
fs.outputJSONSync(versionsPath, { versions: [] }, { spaces: 2 });
}
const versionsJson = fs.readJSONSync(versionsPath);

// Add in or update this new version in the versions file.
const idx = versionsJson.versions.findIndex(vers => vers.output === newVersionData.output);
if (idx === -1) {
versionsJson.versions.push(newVersionData);
} else {
versionsJson.versions[idx] = newVersionData;
}
fs.writeJsonSync(versionsPath, versionsJson, { spaces: 2 });
if (verbose) {
logger.info('versions.json file updated');
}

return versionsJson;
} catch (error) {
await Site.rejectHandler(error, [this.tempPath, this.outputPath]);
return null;
}
}

deploy(ciTokenVar) {
const defaultDeployConfig = {
branch: 'gh-pages',
Expand Down