summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/static_site_editor/services/load_source_content.js
blob: fcf69efafd8424fe4cd411c79498204859f96743 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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;