build(docs-infra): specify more relevant landing files for StackBlitz projects (#34553)
The StackBlitz API (which we use to generate StackBlitz projects on the fly, when a user clicks on a live example link in the docs) allows specifying the file to open in the editor by passing a query param. If no file is specified, StackBlitz opens a default one. This commit specifies relevant landing files for some of the examples to make it easier to engage with the examples more quickly, and to see what the example is attempting to demonstrate. Fixes #22357. PR Close #34553
This commit is contained in:
parent
00f13cc074
commit
77c53559d0
|
@ -116,13 +116,26 @@ class StackblitzBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
_createBaseStackblitzHtml(config) {
|
||||
var file = '';
|
||||
|
||||
// TODO: Doesn't work properly yet
|
||||
_getPrimaryFile(config) {
|
||||
if (config.file) {
|
||||
file = `?file=${config.file}`;
|
||||
if (!this._existsSync(path.join(config.basePath, config.file))) {
|
||||
throw new Error(`The specified primary file (${config.file}) does not exist in '${config.basePath}'.`);
|
||||
}
|
||||
return config.file;
|
||||
} else {
|
||||
const defaultPrimaryFiles = ['src/app/app.component.html', 'src/app/app.component.ts', 'src/app/main.ts'];
|
||||
const primaryFile = defaultPrimaryFiles.find(fileName => this._existsSync(path.join(config.basePath, fileName)));
|
||||
|
||||
if (!primaryFile) {
|
||||
throw new Error(`None of the default primary files (${defaultPrimaryFiles.join(', ')}) exists in '${config.basePath}'.`);
|
||||
}
|
||||
|
||||
return primaryFile;
|
||||
}
|
||||
}
|
||||
|
||||
_createBaseStackblitzHtml(config) {
|
||||
var file = `?file=${this._getPrimaryFile(config)}`;
|
||||
var action = `https://run.stackblitz.com/api/angular/v1${file}`;
|
||||
var html = `<!DOCTYPE html><html lang="en"><body>
|
||||
<form id="mainForm" method="post" action="${action}" target="_self"></form>
|
||||
|
|
Loading…
Reference in New Issue