File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -76,22 +76,29 @@ export function label (thing, initialCap = false): string {
7676 }
7777 }
7878 }
79- if ( s . slice ( - 5 ) === '#this' ) s = s . slice ( 0 , - 5 )
80- else if ( s . slice ( - 3 ) === '#me' ) s = s . slice ( 0 , - 3 )
79+
80+ s = slice ( s , '/profile/card#me' )
81+ s = slice ( s , '#this' )
82+ s = slice ( s , '#me' )
8183
8284 const hash = s . indexOf ( '#' )
8385 if ( hash >= 0 ) return cleanUp ( s . slice ( hash + 1 ) )
8486
85- if ( s . slice ( - 9 ) === '/foaf.rdf' ) s = s . slice ( 0 , - 9 )
86- else if ( s . slice ( - 5 ) === '/foaf' ) s = s . slice ( 0 , - 5 )
87-
8887 // Eh? Why not do this? e.g. dc:title needs it only trim URIs, not rdfs:labels
8988 const slash = s . lastIndexOf ( '/' , s . length - 2 ) // (len-2) excludes trailing slash
9089 if ( slash >= 0 && slash < thing . uri . length ) return cleanUp ( s . slice ( slash + 1 ) )
9190
9291 return doCap ( decodeURIComponent ( thing . uri ) )
9392}
9493
94+ function slice ( s : string , suffix : string ) {
95+ const length = suffix . length * - 1
96+ if ( s . slice ( length ) === suffix ) {
97+ return s . slice ( 0 , length )
98+ }
99+ return s
100+ }
101+
95102// Hard coded known label predicates
96103// @@ TBD: Add subproperties of rdfs:label
97104function getWellKnownLabel ( thing ) {
Original file line number Diff line number Diff line change @@ -65,22 +65,13 @@ describe('label', () => {
6565 } )
6666 it ( 'the last part of the path is used if fragment is #me' , ( ) => {
6767 const result = label (
68- sym ( 'https://resource.example/profile/card #me' )
68+ sym ( 'https://resource.example/path/to/folder/ #me' )
6969 )
70- expect ( result ) . toEqual ( 'card' )
71- } )
72- it ( 'the last part of the path before foaf.rdf is used' , ( ) => {
73- const result = label (
74- sym ( 'https://resource.example/profile/foaf.rdf' )
75- )
76- expect ( result ) . toEqual ( 'profile' )
70+ expect ( result ) . toEqual ( 'folder' )
7771 } )
78-
79- it ( 'the last part of the path before foaf is used' , ( ) => {
80- const result = label (
81- sym ( 'https://resource.example/profile/foaf' )
82- )
83- expect ( result ) . toEqual ( 'profile' )
72+ it ( 'the hostname is used for common WebID URI pattern' , ( ) => {
73+ const result = label ( sym ( 'https://alice.solid.example/profile/card#me' ) )
74+ expect ( result ) . toEqual ( 'alice.solid.example' )
8475 } )
8576 } )
8677
You can’t perform that action at this time.
0 commit comments