mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-08 23:15:28 +02:00
Added ability to change uri manually
This commit is contained in:
parent
77f671b052
commit
bdd5da4ec6
12 changed files with 47 additions and 21 deletions
2
public/dist/main.bundle.js
vendored
2
public/dist/main.bundle.js
vendored
File diff suppressed because one or more lines are too long
2
public/dist/main.css
vendored
2
public/dist/main.css
vendored
File diff suppressed because one or more lines are too long
|
@ -13,7 +13,7 @@ class Aliases {
|
|||
* @returns {Promise<Alias>}
|
||||
*/
|
||||
static async get(aliasName) {
|
||||
const alias = await Alias.get(aliasName.slice(1));
|
||||
const alias = await Alias.get(aliasName);
|
||||
|
||||
if (!alias.id) {
|
||||
throw new Error('Entity with given alias does not exist');
|
||||
|
|
|
@ -117,13 +117,15 @@ class Pages {
|
|||
if (!page._id) {
|
||||
throw new Error('Page with given id does not exist');
|
||||
}
|
||||
const oldAlias = page.uri;
|
||||
const previousUri = page.uri;
|
||||
|
||||
page.data = data;
|
||||
|
||||
const pagePromise = page.save();
|
||||
const updatedPage = await pagePromise;
|
||||
|
||||
Alias.markAsDeprecated(oldAlias);
|
||||
if (updatedPage.uri !== previousUri) {
|
||||
Alias.markAsDeprecated(previousUri);
|
||||
|
||||
const alias = new Alias({
|
||||
id: updatedPage._id,
|
||||
|
@ -132,6 +134,8 @@ class Pages {
|
|||
});
|
||||
|
||||
alias.save();
|
||||
}
|
||||
|
||||
return pagePromise;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,8 @@ export default class Writing {
|
|||
this.nodes = {
|
||||
editorWrapper: null,
|
||||
saveButton: null,
|
||||
parentIdSelector: null
|
||||
parentIdSelector: null,
|
||||
uriInput: null
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -61,6 +62,7 @@ export default class Writing {
|
|||
this.saveButtonClicked();
|
||||
});
|
||||
this.nodes.parentIdSelector = moduleEl.querySelector('[name="parent"]');
|
||||
this.nodes.uriInput = moduleEl.querySelector('[name="uri-input"]');
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -91,6 +93,7 @@ export default class Writing {
|
|||
|
||||
return {
|
||||
parent: this.nodes.parentIdSelector.value,
|
||||
uri: this.nodes.uriInput ? this.nodes.uriInput.value : '',
|
||||
body: editorData
|
||||
};
|
||||
}
|
||||
|
|
|
@ -18,3 +18,13 @@
|
|||
color: var(--color-text-second);
|
||||
}
|
||||
}
|
||||
|
||||
.uri-input {
|
||||
border: 1px solid rgba(201, 201, 204, 0.48);
|
||||
box-shadow: inset 0 1px 2px 0 rgba(35, 44, 72, 0.06);
|
||||
border-radius: 3px;
|
||||
padding: 10px 12px;
|
||||
outline: none;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
--color-text-second: #7B7E89;
|
||||
--color-line-gray: #E8E8EB;
|
||||
--color-link-active: #388AE5;
|
||||
--color-gray-border: rgba(201, 201, 204, 0.48);
|
||||
|
||||
/**
|
||||
* Site layout sizes
|
||||
|
|
|
@ -26,7 +26,11 @@ class Alias {
|
|||
*/
|
||||
static async get(aliasName) {
|
||||
const hash = md5(aliasName);
|
||||
const data = await aliasesDb.findOne({hash});
|
||||
let data = await aliasesDb.findOne({hash: hash, deprecated: false});
|
||||
|
||||
if (!data) {
|
||||
data = await aliasesDb.findOne({hash: hash});
|
||||
}
|
||||
|
||||
return new Alias(data);
|
||||
}
|
||||
|
|
|
@ -148,11 +148,11 @@ class Page {
|
|||
* @returns {Promise<Page>}
|
||||
*/
|
||||
async save() {
|
||||
let newUri = translateString(this.title.toLowerCase()).split(' ').join('-');
|
||||
let newUri = this.uri;
|
||||
let pageWithSameUri = await Page.getByUri(newUri);
|
||||
let pageWithSameUriCount = 0;
|
||||
|
||||
while (pageWithSameUri._id) {
|
||||
while (pageWithSameUri._id && pageWithSameUri._id !== this._id) {
|
||||
pageWithSameUriCount++;
|
||||
pageWithSameUri = await Page.getByUri(newUri + `-${pageWithSameUriCount}`);
|
||||
}
|
||||
|
|
|
@ -11,8 +11,7 @@ const aliasTypes = require('../constants/aliasTypes');
|
|||
*/
|
||||
router.get('*', async (req, res) => {
|
||||
try {
|
||||
console.log('url ', req.originalUrl);
|
||||
const alias = await Aliases.get(req.originalUrl);
|
||||
const alias = await Aliases.get(req.originalUrl.slice(1));
|
||||
|
||||
switch (alias.type) {
|
||||
case aliasTypes.PAGE: {
|
||||
|
|
|
@ -76,8 +76,8 @@ router.post('/page/:id', multer.any(), async (req, res) => {
|
|||
const {id} = req.params;
|
||||
|
||||
try {
|
||||
const {title, body, parent} = req.body;
|
||||
const page = await Pages.update(id, {title, body, parent});
|
||||
const {title, body, parent, uri} = req.body;
|
||||
const page = await Pages.update(id, {title, body, parent, uri});
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
|
|
|
@ -34,5 +34,10 @@
|
|||
Save
|
||||
</span>
|
||||
</header>
|
||||
{% if page is not empty %}
|
||||
<main>
|
||||
<input type="text" class="uri-input" name="uri-input" placeholder="Uri(Optional)" value="{{ page.uri }}">
|
||||
</main>
|
||||
{% endif %}
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue