File tree 2 files changed +16
-19
lines changed
2 files changed +16
-19
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,14 @@ import {
16
16
import { ResolvedCodeRef } from ' @cardstack/runtime-common' ;
17
17
import CodeIcon from ' @cardstack/boxel-icons/code' ;
18
18
19
+ function moduleIsUrlLike(module : string ) {
20
+ return (
21
+ module .startsWith (' http' ) ||
22
+ module .startsWith (' .' ) ||
23
+ module .startsWith (' /' )
24
+ );
25
+ }
26
+
19
27
class BaseView extends Component <typeof CodeRefField > {
20
28
<template >
21
29
<div data-test-ref >
@@ -37,11 +45,11 @@ export default class CodeRefField extends FieldDef {
37
45
_visited ? : Set <string >,
38
46
opts ? : SerializeOpts ,
39
47
) {
40
- const moduleIsUrlLike =
41
- codeRef .module .startsWith (' http' ) || codeRef .module .startsWith (' .' );
42
48
return {
43
49
... codeRef ,
44
- ... (opts ?.maybeRelativeURL && ! opts ?.useAbsoluteURL && moduleIsUrlLike
50
+ ... (opts ?.maybeRelativeURL &&
51
+ ! opts ?.useAbsoluteURL &&
52
+ moduleIsUrlLike (codeRef .module )
45
53
? { module: opts .maybeRelativeURL (codeRef .module ) }
46
54
: {}),
47
55
};
@@ -72,9 +80,7 @@ function maybeSerializeCodeRef(
72
80
stack : CardDef [] = [],
73
81
) {
74
82
if (codeRef ) {
75
- const moduleIsUrlLike =
76
- codeRef .module .startsWith (' http' ) || codeRef .module .startsWith (' .' );
77
- if (moduleIsUrlLike ) {
83
+ if (moduleIsUrlLike (codeRef .module )) {
78
84
// if a stack is passed in, use the containing card to resolve relative references
79
85
let moduleHref =
80
86
stack .length > 0
Original file line number Diff line number Diff line change @@ -11,22 +11,13 @@ import CodeRefField from './code-ref';
11
11
import MarkdownField from ' ./markdown' ;
12
12
import StringField from ' ./string' ;
13
13
import RobotIcon from ' @cardstack/boxel-icons/robot' ;
14
-
15
- function djb2_xor(str : string ) {
16
- let len = str .length ;
17
- let h = 5381 ;
18
-
19
- for (let i = 0 ; i < len ; i ++ ) {
20
- h = (h * 33 ) ^ str .charCodeAt (i );
21
- }
22
- return (h >>> 0 ).toString (16 );
23
- }
14
+ import { simpleHash } from ' @cardstack/runtime-common' ;
24
15
25
16
function friendlyModuleName(fullModuleUrl : string ) {
26
17
return fullModuleUrl
27
18
.split (' /' )
28
- .slice ( - 1 )[ 0 ]
29
- .replace (/ \. gts$ / , ' ' );
19
+ .pop () !
20
+ .replace (/ \. gts$ / , ' ' );
30
21
}
31
22
32
23
export class CommandField extends FieldDef {
@@ -46,7 +37,7 @@ export class CommandField extends FieldDef {
46
37
return ' ' ;
47
38
}
48
39
49
- const hashed = djb2_xor (` ${this .codeRef .module }#${this .codeRef .name } ` );
40
+ const hashed = simpleHash (` ${this .codeRef .module }#${this .codeRef .name } ` );
50
41
let name =
51
42
this .codeRef .name === ' default'
52
43
? friendlyModuleName (this .codeRef .module )
You can’t perform that action at this time.
0 commit comments