mirror of
https://github.com/urbit/shrub.git
synced 2024-11-28 22:33:06 +03:00
handle edge cases in blog/post naming
This commit is contained in:
parent
14b6816300
commit
2f5d2bfb36
@ -47,7 +47,7 @@
|
||||
::
|
||||
++ new-collection
|
||||
%- ot:dejs
|
||||
:~ name+(su:dejs sym)
|
||||
:~ name+so:dejs
|
||||
title+so:dejs
|
||||
comments+comment-config
|
||||
allow-edit+edit-config
|
||||
@ -57,8 +57,8 @@
|
||||
++ new-post
|
||||
%- ot:dejs
|
||||
:~ who+(su:dejs fed:ag)
|
||||
coll+(su:dejs sym)
|
||||
name+(su:dejs sym)
|
||||
coll+so:dejs
|
||||
name+so:dejs
|
||||
title+so:dejs
|
||||
comments+comment-config
|
||||
perm+perm-config
|
||||
@ -68,40 +68,40 @@
|
||||
++ new-comment
|
||||
%- ot:dejs
|
||||
:~ who+(su:dejs fed:ag)
|
||||
coll+(su:dejs sym)
|
||||
coll+so:dejs
|
||||
name+(su:dejs sym)
|
||||
content+so:dejs
|
||||
==
|
||||
::
|
||||
++ delete-collection
|
||||
%- ot:dejs
|
||||
:~ coll+(su:dejs sym)
|
||||
:~ coll+so:dejs
|
||||
==
|
||||
::
|
||||
++ delete-post
|
||||
%- ot:dejs
|
||||
:~ coll+(su:dejs sym)
|
||||
post+(su:dejs sym)
|
||||
:~ coll+so:dejs
|
||||
post+so:dejs
|
||||
==
|
||||
::
|
||||
++ delete-comment
|
||||
%- ot:dejs
|
||||
:~ coll+(su:dejs sym)
|
||||
post+(su:dejs sym)
|
||||
comment+(su:dejs sym)
|
||||
:~ coll+so:dejs
|
||||
post+so:dejs
|
||||
comment+so:dejs
|
||||
==
|
||||
::
|
||||
++ edit-collection
|
||||
%- ot:dejs
|
||||
:~ name+(su:dejs sym)
|
||||
:~ name+so:dejs
|
||||
title+so:dejs
|
||||
==
|
||||
::
|
||||
++ edit-post
|
||||
%- ot:dejs
|
||||
:~ who+(su:dejs fed:ag)
|
||||
coll+(su:dejs sym)
|
||||
name+(su:dejs sym)
|
||||
coll+so:dejs
|
||||
name+so:dejs
|
||||
title+so:dejs
|
||||
comments+comment-config
|
||||
perm+perm-config
|
||||
@ -110,9 +110,9 @@
|
||||
::
|
||||
++ edit-comment
|
||||
%- ot:dejs
|
||||
:~ coll+(su:dejs sym)
|
||||
name+(su:dejs sym)
|
||||
id+(su:dejs sym)
|
||||
:~ coll+so:dejs
|
||||
name+so:dejs
|
||||
id+so:dejs
|
||||
content+so:dejs
|
||||
==
|
||||
::
|
||||
@ -147,7 +147,7 @@
|
||||
::
|
||||
++ invite
|
||||
%- ot:dejs
|
||||
:~ coll+(su:dejs sym)
|
||||
:~ coll+so:dejs
|
||||
title+so:dejs
|
||||
who+(ar:dejs (su:dejs fed:ag))
|
||||
==
|
||||
@ -155,36 +155,36 @@
|
||||
++ reject-invite
|
||||
%- ot:dejs
|
||||
:~ who+(su:dejs fed:ag)
|
||||
coll+(su:dejs sym)
|
||||
coll+so:dejs
|
||||
==
|
||||
::
|
||||
++ serve
|
||||
%- ot:dejs
|
||||
:~ coll+(su:dejs sym)
|
||||
:~ coll+so:dejs
|
||||
==
|
||||
::
|
||||
++ unserve
|
||||
%- ot:dejs
|
||||
:~ coll+(su:dejs sym)
|
||||
:~ coll+so:dejs
|
||||
==
|
||||
::
|
||||
++ subscribe
|
||||
%- ot:dejs
|
||||
:~ who+(su:dejs fed:ag)
|
||||
coll+(su:dejs sym)
|
||||
coll+so:dejs
|
||||
==
|
||||
::
|
||||
++ unsubscribe
|
||||
%- ot:dejs
|
||||
:~ who+(su:dejs fed:ag)
|
||||
coll+(su:dejs sym)
|
||||
coll+so:dejs
|
||||
==
|
||||
::
|
||||
++ read
|
||||
%- ot:dejs
|
||||
:~ who+(su:dejs fed:ag)
|
||||
coll+(su:dejs sym)
|
||||
post+(su:dejs sym)
|
||||
coll+so:dejs
|
||||
post+so:dejs
|
||||
==
|
||||
::
|
||||
--
|
||||
|
@ -82,8 +82,8 @@ export class Blog extends Component {
|
||||
let blogId = this.props.blogId;
|
||||
|
||||
let blog = (ship === window.ship)
|
||||
? _.get(this.props, `pubs[${blogId}]`, false)
|
||||
: _.get(this.props, `subs[${ship}][${blogId}]`, false);
|
||||
? _.get(this.props, `pubs["${blogId}"]`, false)
|
||||
: _.get(this.props, `subs["${ship}"]["${blogId}"]`, false);
|
||||
|
||||
|
||||
if (!(blog) && (ship === window.ship)) {
|
||||
@ -110,8 +110,8 @@ export class Blog extends Component {
|
||||
let ship = this.props.ship;
|
||||
let blogId = this.props.blogId;
|
||||
let blog = (ship == window.ship)
|
||||
? _.get(this.props, `pubs[${blogId}]`, false)
|
||||
: _.get(this.props, `subs[${ship}][${blogId}]`, false);
|
||||
? _.get(this.props, `pubs["${blogId}"]`, false)
|
||||
: _.get(this.props, `subs["${ship}"]["${blogId}"]`, false);
|
||||
|
||||
if (!(blog) && (ship === window.ship)) {
|
||||
this.setState({notFound: true});
|
||||
@ -174,8 +174,8 @@ export class Blog extends Component {
|
||||
|
||||
buildData(){
|
||||
let blog = (this.props.ship == window.ship)
|
||||
? _.get(this.props, `pubs[${this.props.blogId}]`, false)
|
||||
: _.get(this.props, `subs[${this.props.ship}][${this.props.blogId}]`, false);
|
||||
? _.get(this.props, `pubs["${this.props.blogId}"]`, false)
|
||||
: _.get(this.props, `subs["${this.props.ship}"]["${this.props.blogId}"]`, false);
|
||||
|
||||
if (this.state.temporary) {
|
||||
return {
|
||||
@ -228,17 +228,14 @@ export class Blog extends Component {
|
||||
}
|
||||
|
||||
viewSubs() {
|
||||
console.log("view subs");
|
||||
this.setState({view: 'subs'});
|
||||
}
|
||||
|
||||
viewSettings() {
|
||||
console.log("view settings");
|
||||
this.setState({view: 'settings'});
|
||||
}
|
||||
|
||||
viewNotes() {
|
||||
console.log("view notes");
|
||||
this.setState({view: 'notes'});
|
||||
}
|
||||
|
||||
@ -259,7 +256,7 @@ export class Blog extends Component {
|
||||
let subNum = _.get(data.blog, 'subscribers.length', 0);
|
||||
|
||||
let foreign = _.get(this.props,
|
||||
`subs[${this.props.ship}][${this.props.blogId}]`, false);
|
||||
`subs["${this.props.ship}"]["${this.props.blogId}"]`, false);
|
||||
|
||||
let actionType = false;
|
||||
if (this.state.temporary) {
|
||||
|
@ -6,9 +6,6 @@ export class Sigil extends Component {
|
||||
render() {
|
||||
const { props } = this;
|
||||
|
||||
|
||||
console.log("sigil ship", props.ship);
|
||||
|
||||
if (props.ship.length > 14) {
|
||||
return (
|
||||
<div className="bg-black" style={{width: 44, height: 44}}>
|
||||
|
@ -31,9 +31,9 @@ export class PathControl extends Component {
|
||||
if ((last.lastMatch === '/~publish/:ship/:blog/:post') ||
|
||||
(last.lastMatch === '/~publish/:ship/:blog')){
|
||||
blog = (last.lastParams.ship.slice(1) == window.ship)
|
||||
? _.get(this.props, `pubs[${last.lastParams.blog}]`, false)
|
||||
? _.get(this.props, `pubs["${last.lastParams.blog}"]`, false)
|
||||
: _.get(this.props,
|
||||
`subs[${last.lastParams.ship.slice(1)}][${last.lastParams.blog}]`, false);
|
||||
`subs["${last.lastParams.ship.slice(1)}"]["${last.lastParams.blog}"]`, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import { Link } from 'react-router-dom';
|
||||
import { PathControl } from '/components/lib/path-control';
|
||||
import { withRouter } from 'react-router';
|
||||
import urbitOb from 'urbit-ob';
|
||||
import { stringToSymbol } from '/lib/util';
|
||||
|
||||
const PC = withRouter(PathControl);
|
||||
|
||||
@ -41,28 +42,10 @@ export class NewBlog extends Component {
|
||||
this.blogSubmit = this.blogSubmit.bind(this);
|
||||
}
|
||||
|
||||
stringToSymbol(str){
|
||||
let result = '';
|
||||
for (var i=0; i<str.length; i++){
|
||||
var n = str.charCodeAt(i);
|
||||
if (( (n >= 97) && (n <= 122) ) ||
|
||||
( (n >= 48) && (n <= 57) ))
|
||||
{
|
||||
result += str[i];
|
||||
} else if ( (n >= 65) && (n <= 90) )
|
||||
{
|
||||
result += String.fromCharCode(n + 32);
|
||||
} else {
|
||||
result += '-';
|
||||
}
|
||||
}
|
||||
return result.replace(/^\-+|\-+$/g, '');
|
||||
}
|
||||
|
||||
blogSubmit() {
|
||||
let ship = window.ship;
|
||||
let blogTitle = this.state.title;
|
||||
let blogId = this.stringToSymbol(blogTitle);
|
||||
let blogId = stringToSymbol(blogTitle);
|
||||
|
||||
let permissions = {
|
||||
read: {
|
||||
|
@ -4,6 +4,7 @@ import { Link } from 'react-router-dom';
|
||||
import _ from 'lodash';
|
||||
import { PathControl } from '/components/lib/path-control';
|
||||
import { withRouter } from 'react-router';
|
||||
import { stringToSymbol } from '/lib/util';
|
||||
|
||||
const PC = withRouter(PathControl);
|
||||
|
||||
@ -67,8 +68,6 @@ export class NewPost extends Component {
|
||||
constructor(props){
|
||||
super(props);
|
||||
|
||||
console.log("props", this.props);
|
||||
|
||||
this.state = {
|
||||
title: "",
|
||||
body: "",
|
||||
@ -92,24 +91,6 @@ export class NewPost extends Component {
|
||||
this.comments = false;
|
||||
}
|
||||
|
||||
stringToSymbol(str){
|
||||
let result = '';
|
||||
for (var i=0; i<str.length; i++){
|
||||
var n = str.charCodeAt(i);
|
||||
if (( (n >= 97) && (n <= 122) ) ||
|
||||
( (n >= 48) && (n <= 57) ))
|
||||
{
|
||||
result += str[i];
|
||||
} else if ( (n >= 65) && (n <= 90) )
|
||||
{
|
||||
result += String.fromCharCode(n + 32);
|
||||
} else {
|
||||
result += '-';
|
||||
}
|
||||
}
|
||||
return result.replace(/^\-+|\-+$/g, '');
|
||||
}
|
||||
|
||||
postSubmit() {
|
||||
let last = _.get(this.props, 'location.state', false);
|
||||
let ship = window.ship;
|
||||
@ -121,7 +102,7 @@ export class NewPost extends Component {
|
||||
}
|
||||
|
||||
let postTitle = this.state.title;
|
||||
let postId = this.stringToSymbol(postTitle);
|
||||
let postId = stringToSymbol(postTitle);
|
||||
|
||||
let awaiting = Object.assign({}, {
|
||||
ship: ship,
|
||||
@ -202,17 +183,17 @@ export class NewPost extends Component {
|
||||
if (ship == window.ship) {
|
||||
post =
|
||||
_.get(this.props,
|
||||
`pubs[${blogId}].posts[${postId}].post`, false) || false;
|
||||
`pubs["${blogId}"].posts["${postId}"].post`, false) || false;
|
||||
comments =
|
||||
_.get(this.props,
|
||||
`pubs[${blogId}].posts[${postId}].comments`, false) || false;
|
||||
`pubs["${blogId}"].posts["${postId}"].comments`, false) || false;
|
||||
} else {
|
||||
post =
|
||||
_.get(this.props,
|
||||
`subs[${ship}][${blogId}].posts[${postId}].post`, false) || false;
|
||||
`subs["${ship}"]["${blogId}"].posts["${postId}"].post`, false) || false;
|
||||
comments =
|
||||
_.get(this.props,
|
||||
`subs[${ship}][${blogId}].posts[${postId}].comments`, false) || false;
|
||||
`subs["${ship}"]["${blogId}"].posts["${postId}"].comments`, false) || false;
|
||||
}
|
||||
|
||||
if (!_.isEqual(this.post, post)) {
|
||||
|
@ -159,11 +159,11 @@ export class Post extends Component {
|
||||
|
||||
if (ship !== window.ship) {
|
||||
|
||||
let blog = _.get(this.props, `subs[${ship}][${blogId}]`, false);
|
||||
let blog = _.get(this.props, `subs["${ship}"]["${blogId}"]`, false);
|
||||
|
||||
if (blog) {
|
||||
let post = _.get(blog, `posts[${postId}].post`, false);
|
||||
let comments = _.get(blog, `posts[${postId}].comments`, false);
|
||||
let post = _.get(blog, `posts["${postId}"].post`, false);
|
||||
let comments = _.get(blog, `posts["${postId}"].comments`, false);
|
||||
let blogUrl = `/~publish/${blog.info.owner}/${blog.info.filename}`;
|
||||
let postUrl = `${blogUrl}/${post.info.filename}`;
|
||||
|
||||
@ -208,9 +208,9 @@ export class Post extends Component {
|
||||
this.handleError.bind(this));
|
||||
}
|
||||
} else {
|
||||
let blog = _.get(this.props, `pubs[${blogId}]`, false);
|
||||
let post = _.get(blog, `posts[${postId}].post`, false);
|
||||
let comments = _.get(blog, `posts[${postId}].comments`, false);
|
||||
let blog = _.get(this.props, `pubs["${blogId}"]`, false);
|
||||
let post = _.get(blog, `posts["${postId}"].post`, false);
|
||||
let comments = _.get(blog, `posts["${postId}"].comments`, false);
|
||||
|
||||
if (!blog || !post) {
|
||||
this.setState({notFound: true});
|
||||
@ -303,13 +303,13 @@ export class Post extends Component {
|
||||
let blog;
|
||||
|
||||
if (ship === window.ship) {
|
||||
blog = _.get(this.props, `pubs[${blogId}]`, false);
|
||||
post = _.get(blog, `posts[${postId}].post`, false);
|
||||
comments = _.get(blog, `posts[${postId}].comments`, false);
|
||||
blog = _.get(this.props, `pubs["${blogId}"]`, false);
|
||||
post = _.get(blog, `posts["${postId}"].post`, false);
|
||||
comments = _.get(blog, `posts["${postId}"].comments`, false);
|
||||
} else {
|
||||
blog = _.get(this.props, `subs[${ship}][${blogId}]`, false);
|
||||
post = _.get(blog, `posts[${postId}].post`, false);
|
||||
comments = _.get(blog, `posts[${postId}].comments`, false);
|
||||
blog = _.get(this.props, `subs["${ship}"]["${blogId}"]`, false);
|
||||
post = _.get(blog, `posts["${postId}"].post`, false);
|
||||
comments = _.get(blog, `posts["${postId}"].comments`, false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,9 +1,6 @@
|
||||
import React, { Component } from 'react';
|
||||
import { BrowserRouter, Route } from "react-router-dom";
|
||||
import Mousetrap from 'mousetrap';
|
||||
import classnames from 'classnames';
|
||||
import _ from 'lodash';
|
||||
|
||||
import { api } from '/api';
|
||||
import { store } from '/store';
|
||||
import { Recent } from '/components/recent';
|
||||
|
38
pkg/interface/publish/src/js/lib/util.js
Normal file
38
pkg/interface/publish/src/js/lib/util.js
Normal file
@ -0,0 +1,38 @@
|
||||
export function stringToSymbol(str) {
|
||||
let result = '';
|
||||
for (var i=0; i<str.length; i++){
|
||||
var n = str.charCodeAt(i);
|
||||
if (( (n >= 97) && (n <= 122) ) ||
|
||||
( (n >= 48) && (n <= 57) ))
|
||||
{
|
||||
result += str[i];
|
||||
} else if ( (n >= 65) && (n <= 90) )
|
||||
{
|
||||
result += String.fromCharCode(n + 32);
|
||||
} else {
|
||||
result += '-';
|
||||
}
|
||||
}
|
||||
result = result.replace(/^[\-\d]+|\-+/g, '-');
|
||||
result = result.replace(/^\-+|\-+$/g, '');
|
||||
if (result === ''){
|
||||
return dateToDa(new Date());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
export function dateToDa(d, mil) {
|
||||
var fil = function(n) {
|
||||
return n >= 10 ? n : "0" + n;
|
||||
};
|
||||
return (
|
||||
`~${d.getUTCFullYear()}.` +
|
||||
`${(d.getUTCMonth() + 1)}.` +
|
||||
`${fil(d.getUTCDate())}..` +
|
||||
`${fil(d.getUTCHours())}.` +
|
||||
`${fil(d.getUTCMinutes())}.` +
|
||||
`${fil(d.getUTCSeconds())}` +
|
||||
`${mil ? "..0000" : ""}`
|
||||
);
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
import { api } from '/api';
|
||||
import _ from 'lodash';
|
||||
import { store } from '/store';
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user