Skip to content

Commit 741f287

Browse files
committed
re: #524, slugify example titles so that they can have a permanent link
1 parent 8dada77 commit 741f287

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

client/modules/IDE/components/SketchList.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { connect } from 'react-redux';
77
import { Link } from 'react-router';
88
import { bindActionCreators } from 'redux';
99
import classNames from 'classnames';
10+
import slugify from 'slugify';
1011
import * as ProjectActions from '../actions/project';
1112
import * as ProjectsActions from '../actions/projects';
1213
import * as ToastActions from '../actions/toast';
@@ -137,13 +138,17 @@ class SketchListRowBase extends React.Component {
137138
const { sketch, username } = this.props;
138139
const { renameOpen, optionsOpen, renameValue } = this.state;
139140
const userIsOwner = this.props.user.username === this.props.username;
141+
let url = `/${username}/sketches/${sketch.id}`;
142+
if (username === 'p5') {
143+
url = `/${username}/sketches/${slugify(sketch.name, '_')}`;
144+
}
140145
return (
141146
<tr
142147
className="sketches-table__row"
143148
key={sketch.id}
144149
>
145150
<th scope="row">
146-
<Link to={`/${username}/sketches/${sketch.id}`}>
151+
<Link to={url}>
147152
{renameOpen ? '' : sketch.name}
148153
</Link>
149154
{renameOpen

server/scripts/examples.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function getCategories() {
6161
for (let j = 1; j < metadata.name.split('_').length; j += 1) {
6262
category += `${metadata.name.split('_')[j]} `;
6363
}
64-
categories.push({ url: metadata.url, name: category });
64+
categories.push({ url: metadata.url, name: category.trim() });
6565
});
6666

6767
return categories;
@@ -114,7 +114,7 @@ function getSketchContent(projectsInAllCategories) {
114114

115115
return rp(options).then((res) => {
116116
const noNumberprojectName = project.projectName.replace(/(\d+)/g, '');
117-
if (noNumberprojectName === 'Instance Mode : Instance Container ') {
117+
if (noNumberprojectName === 'Instance Mode: Instance Container ') {
118118
for (let i = 0; i < 4; i += 1) {
119119
const splitedRes = `${res.split('*/')[1].split('</html>')[i]}</html>\n`;
120120
project.sketchContent = splitedRes.replace(
@@ -153,7 +153,7 @@ function createProjectsInP5user(projectsInAllCategories) {
153153
const c = objectID().toHexString();
154154
const r = objectID().toHexString();
155155
const noNumberprojectName = project.projectName.replace(/(\d+)/g, '');
156-
if (noNumberprojectName === 'Instance Mode : Instance Container ') {
156+
if (noNumberprojectName === 'Instance Mode: Instance Container ') {
157157
newProject = new Project({
158158
name: project.projectName,
159159
user: user._id,
@@ -167,7 +167,7 @@ function createProjectsInP5user(projectsInAllCategories) {
167167
},
168168
{
169169
name: 'sketch.js',
170-
content: '// Instance Mode : Instance Container, please check its index.html file',
170+
content: '// Instance Mode: Instance Container, please check its index.html file',
171171
id: a,
172172
_id: a,
173173
fileType: 'file',

0 commit comments

Comments
 (0)