-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: preview server configuration and usage (#77)
* Loads a preview server config from the editor config file. * When files are loaded without urls the preview server config is loaded to check if the preview server has a known path for the file.
- Loading branch information
Showing
9 changed files
with
763 additions
and
294 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
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,53 @@ | ||
import {EditorPreviewSettings, WorkspaceData} from './api'; | ||
import {interpolate} from '../utility/stringLiteral'; | ||
import {shortenWorkspaceName} from './workspace'; | ||
|
||
/** | ||
* Uses string literals to convert a preview server url into a full url. | ||
* | ||
* @param settings Editor preview settings. | ||
* @param workspace Workspace to generate the url for. | ||
* @returns Interpolated url for the base preview server. | ||
*/ | ||
export function interpolatePreviewBaseUrl( | ||
settings: EditorPreviewSettings, | ||
workspace: WorkspaceData, | ||
params?: Record<string, string> | ||
) { | ||
params = params ?? { | ||
workspace: shortenWorkspaceName(workspace.name), | ||
workspaceFull: workspace.name, | ||
}; | ||
return interpolate(params, settings.baseUrl); | ||
} | ||
|
||
/** | ||
* Uses string literals to convert a preview server url into a full url. | ||
* | ||
* Specific to for loading the settings config file. | ||
* | ||
* @param settings Editor preview settings. | ||
* @param workspace Workspace to generate the url for. | ||
* @returns Interpolated url for the base preview server. | ||
*/ | ||
export function interpolatePreviewConfigUrl( | ||
settings: EditorPreviewSettings, | ||
workspace: WorkspaceData | ||
) { | ||
const params = { | ||
workspace: shortenWorkspaceName(workspace.name), | ||
workspaceFull: workspace.name, | ||
baseUrl: '', | ||
}; | ||
|
||
params.baseUrl = interpolatePreviewBaseUrl(settings, workspace, params); | ||
|
||
if (settings.configUrl) { | ||
return interpolate(params, settings.configUrl); | ||
} | ||
|
||
// Default to the `preview.json` file. | ||
return `${params.baseUrl}${ | ||
params.baseUrl.endsWith('/') ? '' : '/' | ||
}preview.json`; | ||
} |
Oops, something went wrong.