diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-06 18:10:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-06 18:10:04 +0300 |
commit | f3b1e07903a7f509b11ad7cf188fac46d98f77f6 (patch) | |
tree | a6fa5e65d83d94334387952f1f526ed438604408 /app/assets/javascripts | |
parent | ba174c982f40d71a87fd511b091753807174f7e7 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r-- | app/assets/javascripts/api.js | 9 | ||||
-rw-r--r-- | app/assets/javascripts/static_site_editor/services/load_source_content.js | 15 |
2 files changed, 24 insertions, 0 deletions
diff --git a/app/assets/javascripts/api.js b/app/assets/javascripts/api.js index 797eaf629bf..75f7fe62a7e 100644 --- a/app/assets/javascripts/api.js +++ b/app/assets/javascripts/api.js @@ -47,6 +47,7 @@ const Api = { adminStatisticsPath: '/api/:version/application/statistics', pipelineSinglePath: '/api/:version/projects/:id/pipelines/:pipeline_id', environmentsPath: '/api/:version/projects/:id/environments', + rawFilePath: '/api/:version/projects/:id/repository/files/:path/raw', group(groupId, callback) { const url = Api.buildUrl(Api.groupPath).replace(':id', groupId); @@ -497,6 +498,14 @@ const Api = { return axios.get(url); }, + getRawFile(id, path, params = { ref: 'master' }) { + const url = Api.buildUrl(this.rawFilePath) + .replace(':id', encodeURIComponent(id)) + .replace(':path', encodeURIComponent(path)); + + return axios.get(url, { params }); + }, + buildUrl(url) { return joinPaths(gon.relative_url_root || '', url.replace(':version', gon.api_version)); }, diff --git a/app/assets/javascripts/static_site_editor/services/load_source_content.js b/app/assets/javascripts/static_site_editor/services/load_source_content.js new file mode 100644 index 00000000000..1af93a8a2bc --- /dev/null +++ b/app/assets/javascripts/static_site_editor/services/load_source_content.js @@ -0,0 +1,15 @@ +import Api from '~/api'; + +const extractTitle = content => { + const matches = content.match(/title: (.+)\n/i); + + return matches ? Array.from(matches)[1] : ''; +}; + +const loadSourceContent = ({ projectId, sourcePath }) => + Api.getRawFile(projectId, sourcePath).then(({ data }) => ({ + title: extractTitle(data), + content: data, + })); + +export default loadSourceContent; |