mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
added to core queryIndexer, used for index an input rules and returns parsed string with callback
This commit is contained in:
parent
98e2db0b70
commit
75af51f0ea
@ -29,6 +29,29 @@ export const app_info = {
|
|||||||
layout: platform.layout
|
layout: platform.layout
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function queryIndexer(array, callback, params) {
|
||||||
|
if(!array) return false
|
||||||
|
|
||||||
|
if (Array.isArray(array)) {
|
||||||
|
let opt = {
|
||||||
|
regex: /:id/gi
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params) {
|
||||||
|
opt = { ...opt, ...params }
|
||||||
|
}
|
||||||
|
|
||||||
|
array.forEach((e) =>{
|
||||||
|
if (e.match != null && e.to != null) {
|
||||||
|
const pathMatch = pathMatchRegexp(e.match, window.location.pathname)
|
||||||
|
if (pathMatch != null) {
|
||||||
|
return callback(e.to.replace(opt.regex, pathMatch[1]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function createScreenshotFromElement(element){
|
export function createScreenshotFromElement(element){
|
||||||
if (!element) return false
|
if (!element) return false
|
||||||
html2canvas(element, {
|
html2canvas(element, {
|
||||||
@ -341,7 +364,6 @@ export const time = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function pathMatchRegexp(regexp, pathname) {
|
export function pathMatchRegexp(regexp, pathname) {
|
||||||
console.log('Regex => ', pathname)
|
|
||||||
return pathToRegexp(regexp).exec(pathname)
|
return pathToRegexp(regexp).exec(pathname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import { user, session } from 'core/helpers'
|
|||||||
import { router, verbosity, appInterface } from 'core/libs'
|
import { router, verbosity, appInterface } from 'core/libs'
|
||||||
import settings from 'core/libs/settings'
|
import settings from 'core/libs/settings'
|
||||||
import { uri_resolver } from 'api/lib'
|
import { uri_resolver } from 'api/lib'
|
||||||
|
import { queryIndexer } from 'core'
|
||||||
|
|
||||||
import jwt from 'jsonwebtoken'
|
import jwt from 'jsonwebtoken'
|
||||||
import cookie from 'cookie_js'
|
import cookie from 'cookie_js'
|
||||||
@ -94,6 +95,28 @@ export default {
|
|||||||
|
|
||||||
window.PluginGlobals = []
|
window.PluginGlobals = []
|
||||||
|
|
||||||
|
queryIndexer([
|
||||||
|
{
|
||||||
|
match: '/s;:id',
|
||||||
|
to: `/settings?key=:id`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
match: '/h;:id',
|
||||||
|
to: `/hashtag?key=:id`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
match: '/p;:id',
|
||||||
|
to: `/post?key=:id`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
match: '/@:id',
|
||||||
|
to: `/@/:id`,
|
||||||
|
}
|
||||||
|
], (callback) => {
|
||||||
|
window.location = callback
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
if (!service) {
|
if (!service) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
21
src/pages/@/[user].js
Normal file
21
src/pages/@/[user].js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { pathMatchRegexp } from 'core'
|
||||||
|
import { router } from 'core/libs/router'
|
||||||
|
import { Invalid } from 'components'
|
||||||
|
|
||||||
|
export default class UserIndexer extends React.Component {
|
||||||
|
render() {
|
||||||
|
const { location } = this.props
|
||||||
|
const matchRegexp = pathMatchRegexp('/@/:id', location.pathname)
|
||||||
|
|
||||||
|
if (matchRegexp) {
|
||||||
|
return (
|
||||||
|
<div style={{ height: "100%" }}>
|
||||||
|
{matchRegexp[1]}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return <Invalid type="index" messageProp1={location.pathname} />
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,29 +1,9 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { pathMatchRegexp } from 'core'
|
|
||||||
import Error404 from './404.js'
|
import Error404 from './404.js'
|
||||||
// <UserProfile {...this.props} regx={matchUser} />
|
|
||||||
import { Invalid } from 'components'
|
|
||||||
|
|
||||||
class PageIndexer extends React.Component {
|
export default class PageIndexer extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
const { location } = this.props
|
const { location } = this.props
|
||||||
const matchUser = pathMatchRegexp('/@:id', location.pathname)
|
|
||||||
const matchSetting = pathMatchRegexp('/~:id', location.pathname)
|
|
||||||
console.log(matchSetting)
|
|
||||||
if (matchUser) {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{matchUser}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (matchSetting) {
|
|
||||||
return(
|
|
||||||
<div>
|
|
||||||
<Invalid type="skeleton" />
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// By default return Error 404
|
// By default return Error 404
|
||||||
return (
|
return (
|
||||||
@ -32,6 +12,4 @@ class PageIndexer extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default PageIndexer
|
|
Loading…
x
Reference in New Issue
Block a user