chore: update and document edit route (#2619)

* chore: update and document edit route

* fix formatting
This commit is contained in:
Shawn Erquhart 2019-09-03 20:37:31 -04:00 committed by GitHub
parent 211577e263
commit 1aff33e158
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 33 deletions

View File

@ -23,8 +23,6 @@ import Workflow from 'Workflow/Workflow';
import Editor from 'Editor/Editor';
import NotFoundPage from './NotFoundPage';
import Header from './Header';
import { selectEntrySlug } from 'Reducers/collections';
import { FILES, FOLDER } from 'Constants/collectionTypes';
TopBarProgress.config({
barColors: {
@ -160,36 +158,6 @@ class App extends React.Component {
const defaultPath = `/collections/${collections.first().get('name')}`;
const hasWorkflow = publishMode === EDITORIAL_WORKFLOW;
const getCustomEditRoute = props => {
const { folder, filename } = props.match.params;
let redirect = null;
const collections = config.get('collections');
const setTypeOnCollection = collection => {
if (collection.has('folder')) return collection.set('type', FOLDER);
if (collection.has('files')) return collection.set('type', FILES);
};
collections.forEach(collection => {
const typedCollection = setTypeOnCollection(collection);
if (typedCollection.has('files')) {
const files = typedCollection.get('files');
files.forEach(file => {
if (file.get('file').includes(`${folder}/${filename}`)) {
redirect = `/collections/${filename}`;
}
});
} else if (typedCollection.has('folder') && folder === typedCollection.get('folder')) {
const slug = selectEntrySlug(typedCollection, filename);
redirect = `/collections/${typedCollection.get('name')}/entries/${slug}`;
}
});
if (redirect !== null) {
return <Redirect to={redirect} />;
}
return <NotFoundPage />;
};
return (
<>
<Notifs CustomComponent={Toast} />
@ -226,7 +194,13 @@ class App extends React.Component {
path="/search/:searchTerm"
render={props => <Collection {...props} isSearchResults />}
/>
<Route path="/edit/:folder/:filename" render={props => getCustomEditRoute(props)} />
<Route
path="/edit/:collectionName/:entryName"
render={({ match }) => {
const { collectionName, entryName } = match.params;
return <Redirect to={`/collections/${collectionName}/entries/${entryName}`} />;
}}
/>
<Route component={NotFoundPage} />
</Switch>
{useMediaLibrary ? <MediaLibrary /> : null}

View File

@ -47,3 +47,24 @@ Users who _do_ have write access to the original repository continue to use the
- Users don't need to know about GitHub or create a GitHub account. Instead, they use Netlify Identity accounts that are created on your site and managed by you.
- The CMS applies users' changes directly to your repo, not to a fork. (If you use the editorial workflow, you can use features like [GitHub's protected branches](https://help.github.com/en/articles/about-protected-branches) or [Netlify's locked deploys](https://www.netlify.com/docs/locked-deploys/) to prevent users from publishing directly to your site from the CMS.)
- There is no distinction between users with write access to the repo and users without — all editorial workflow entries are visible from within the CMS and can be published with the CMS. (Unpublished Open Authoring entries, on the other hand, are visible only to the author in the CMS UI or publicly as GitHub PRs.)
## Linking to specific entries in the CMS
Open authoring often includes some sort of "Edit this page" link on the live site. Netlify CMS supports this via the **edit** path:
```
/#/edit/{collectionName}/{entryName}
```
For the entry named "general" in the "settings" file collection
```
https://www.example.com/path-to-cms/#/edit/settings/general
```
For blog post "test.md" in the "posts" folder collection
```
https://www.example.com/path-to-cms/#/edit/posts/test
```
- **`collectionName`**: the name of the collection as entered in the CMS config.
- **`entryName`** _(for [file collections](/docs/collection-types/#file-collections)_: the `name` of the entry from the CMS config.
- **`entryName`** _(for [folder collections](/docs/collection-types/#folder-collections)_: the filename, sans extension (the slug).