Skip to content

Commit aa88bb9

Browse files
committed
more intelligent support for variable root_urls
1 parent 8117d9e commit aa88bb9

File tree

6 files changed

+41
-9
lines changed

6 files changed

+41
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Parameters:
2323
| `element` | `#socket` | The id of the element created |
2424
| `router_mode` | `hash` | The routing mode when clicking on a tutor's profile. |
2525
| `mode` | `grid` | Which mode you want to use (explained below) |
26-
| `url_root` | `\` | The root URL of the page you are using Socket from eg. '/our-tutors/'|
26+
| `url_root` | `/` | The root URL of the page you are using Socket from eg. '/our-tutors/'|
2727

2828
We use some strings within Socket that you may want to change by passing them as parameters also.
2929

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tutorcruncher-socket",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "TutorCruncher socket",
55
"author": "Samuel Colvin <[email protected]>",
66
"private": false,

src/components/footer.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ export default {}
4040
color: $brand-colour;
4141
svg {
4242
opacity: 1;
43+
transform: translate(0, 8px);
4344
}
4445
}
4546
svg {
4647
transition: all .8s ease;
4748
width: 25px;
4849
height: 25px;
49-
transform: translate(0, 8px);
50+
transform: translate(0px, 4px);
5051
opacity: 0;
5152
path {
5253
fill: $hightlight;

src/main.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import enquiry_button from './components/enquiry-button'
88
import enquiry_modal from './components/enquiry-modal'
99
import grid from './components/grid'
1010
import con_modal from './components/con-modal'
11-
import {to_markdown, clean} from './utils'
11+
import {to_markdown, clean, auto_url_root} from './utils'
1212

1313
let dsn = process.env.NODE_ENV === 'production' && 'https://[email protected]/128441'
1414
Raven.config(dsn, {release: process.env.RELEASE}).addPlugin(RavenVue, Vue).install()
@@ -91,12 +91,16 @@ module.exports = function (public_key, config) {
9191
}
9292

9393
if (config.url_root === undefined) {
94-
config.url_root = window.location.pathname
95-
} else if (config.url_root[0] !== '/') {
96-
config.url_root = window.location.pathname
94+
config.url_root = 'auto'
95+
} else if (config.url_root !== 'auto' && config.url_root[0] !== '/') {
96+
config.url_root = '/'
9797
error = 'the "url_root" config parameter should start (and probably end) with a slash "/"'
9898
}
9999

100+
if (config.url_root === 'auto') {
101+
config.url_root = auto_url_root(window.location.pathname)
102+
}
103+
100104
if (config.router_mode === undefined) {
101105
config.router_mode = 'hash'
102106
} else if (ROUTER_MODES.indexOf(config.router_mode) === -1) {

src/utils.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ marked.setOptions({
66
smartLists: true,
77
})
88

9-
function to_markdown (t) {
9+
const to_markdown = (t) => {
1010
if (t === null || t === undefined) {
1111
return ''
1212
} else {
@@ -26,4 +26,12 @@ const clean = (obj) => {
2626
return new_obj
2727
}
2828

29-
export { to_markdown, clean }
29+
const auto_url_root = (path) => {
30+
// remove :
31+
// * contractor slug
32+
// * /enquiry
33+
path = path.replace(/\/\d+-[\w-]+$/, '/').replace(/\/enquiry$/, '/')
34+
return path
35+
}
36+
37+
export {to_markdown, clean, auto_url_root}

test/unit/specs/utils.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {auto_url_root} from 'src/utils'
2+
3+
describe('utils.js.auto_url_root', () => {
4+
it('should remove /enquiry', () => {
5+
expect(auto_url_root('/foobar/bar/enquiry')).equal('/foobar/bar/')
6+
})
7+
8+
it('should not remove /enquiry/', () => {
9+
expect(auto_url_root('/foobar/bar/enquiry/')).equal('/foobar/bar/enquiry/')
10+
})
11+
12+
it('should remove /123-frank-s', () => {
13+
expect(auto_url_root('/123-frank-s')).equal('/')
14+
})
15+
16+
it('should not remove /-frank-s', () => {
17+
expect(auto_url_root('/-frank-s')).equal('/-frank-s')
18+
})
19+
})

0 commit comments

Comments
 (0)