Skip to content

Commit 137411d

Browse files
mjcuvaerunion
andauthored
fix: allow customers to define the slug in the metadata (#375)
* fix: allow customers to define the slug in the metadata * chore: replacing a real looking category id in a test with a fake one Co-authored-by: Jon Ursenbach <jon@ursenba.ch>
1 parent fd383f9 commit 137411d

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
category: CATEGORY_ID
3+
title: This is the document title
4+
slug: marc-actually-wrote-a-test
5+
---
6+
7+
Body

__tests__/cmds/docs.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,40 @@ describe('rdme docs', () => {
277277
});
278278
});
279279
});
280+
281+
describe('slug metadata', () => {
282+
it('should use provided slug', () => {
283+
const slug = 'new-doc-slug';
284+
const doc = frontMatter(fs.readFileSync(path.join(fixturesDir, `/slug-docs/${slug}.md`)));
285+
const hash = hashFileContents(fs.readFileSync(path.join(fixturesDir, `/slug-docs/${slug}.md`)));
286+
287+
const getMock = getNockWithVersionHeader(version)
288+
.get(`/api/v1/docs/${doc.data.slug}`)
289+
.basicAuth({ user: key })
290+
.reply(404, {
291+
error: 'DOC_NOTFOUND',
292+
message: `The doc with the slug '${slug}' couldn't be found`,
293+
suggestion: '...a suggestion to resolve the issue...',
294+
help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".',
295+
});
296+
297+
const postMock = getNockWithVersionHeader(version)
298+
.post(`/api/v1/docs`, { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash })
299+
.basicAuth({ user: key })
300+
.reply(201, { slug: doc.data.slug, body: doc.content, ...doc.data, lastUpdatedHash: hash });
301+
302+
const versionMock = nock(config.host)
303+
.get(`/api/v1/version/${version}`)
304+
.basicAuth({ user: key })
305+
.reply(200, { version });
306+
307+
return docs.run({ folder: './__tests__/__fixtures__/slug-docs', key, version }).then(() => {
308+
getMock.done();
309+
postMock.done();
310+
versionMock.done();
311+
});
312+
});
313+
});
280314
});
281315

282316
describe('rdme docs:edit', () => {

src/cmds/docs/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ exports.run = async function (opts) {
116116
const matter = frontMatter(file);
117117

118118
// Stripping the subdirectories and markdown extension from the filename and lowercasing to get the default slug.
119-
const slug = path.basename(filename).replace(path.extname(filename), '').toLowerCase();
119+
const slug = matter.data.slug || path.basename(filename).replace(path.extname(filename), '').toLowerCase();
120120
const hash = crypto.createHash('sha1').update(file).digest('hex');
121121

122122
return fetch(`${config.host}/api/v1/docs/${slug}`, {

0 commit comments

Comments
 (0)