erudit 3.0.0-dev.6 → 3.0.0-dev.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/app/components/SiteMain.vue +2 -3
  2. package/app/components/aside/minor/topic/TopicToc.vue +1 -1
  3. package/app/components/bitran/BitranContent.vue +10 -3
  4. package/app/components/main/topic/MainTopic.vue +1 -2
  5. package/app/components/main/utils/Breadcrumb.vue +1 -6
  6. package/app/components/main/utils/ContentPopovers.vue +11 -5
  7. package/app/components/preview/display/Unique.vue +7 -1
  8. package/app/composables/bitran.ts +11 -35
  9. package/app/composables/bitranContent.ts +16 -4
  10. package/app/composables/bitranLocation.ts +1 -1
  11. package/app/pages/group/[...groupId].vue +3 -4
  12. package/app/scripts/preview/data/unique.ts +6 -5
  13. package/bin/erudit.mjs +2 -0
  14. package/module/bitran.ts +3 -2
  15. package/module/config.ts +2 -1
  16. package/module/index.ts +5 -5
  17. package/nuxt.config.ts +8 -2
  18. package/package.json +13 -9
  19. package/server/api/aside/major/nav/global.ts +1 -1
  20. package/server/api/aside/minor/path.ts +1 -2
  21. package/server/api/preview/page/[...parts].ts +3 -2
  22. package/server/api/preview/unique/[location].ts +6 -3
  23. package/server/plugin/bitran/content.ts +49 -42
  24. package/server/plugin/bitran/location.ts +1 -1
  25. package/server/plugin/bitran/products/include.ts +13 -15
  26. package/server/plugin/bitran/products/link.ts +12 -12
  27. package/server/plugin/bitran/setup.ts +1 -1
  28. package/server/plugin/bitran/toc.ts +21 -29
  29. package/server/plugin/bitran/transpiler.ts +2 -20
  30. package/server/plugin/build/jobs/content/parse.ts +19 -10
  31. package/server/plugin/build/setup.ts +1 -0
  32. package/server/plugin/content/absoluteId.ts +1 -1
  33. package/server/plugin/content/context.ts +1 -1
  34. package/server/plugin/db/entities/Content.ts +1 -1
  35. package/shared/aside/minor.ts +2 -1
  36. package/shared/bitran/stringContent.ts +6 -0
  37. package/shared/icons.ts +1 -1
  38. package/shared/link.ts +5 -2
  39. package/tsconfig.json +1 -1
  40. package/shared/bitran/context.ts +0 -8
  41. package/shared/bitran/default.ts +0 -46
  42. package/shared/bitran/link/Link.vue +0 -166
  43. package/shared/bitran/link/factory.ts +0 -24
  44. package/shared/bitran/link/icon.svg +0 -3
  45. package/shared/bitran/link/languages/en.ts +0 -7
  46. package/shared/bitran/link/languages/ru.ts +0 -7
  47. package/shared/bitran/link/renderer.ts +0 -21
  48. package/shared/bitran/link/shared.ts +0 -17
  49. package/shared/bitran/link/target.ts +0 -134
  50. package/shared/bitran/link/transpiler.ts +0 -10
  51. package/shared/bitran/location.ts +0 -166
  52. package/test/bitran/link/target.test.ts +0 -141
  53. package/test/bitran/location.test.ts +0 -143
@@ -1,141 +0,0 @@
1
- import { NO_ALIASES } from '@erudit-js/bitran-elements/aliases/shared';
2
-
3
- console.log(NO_ALIASES());
4
-
5
- import type { BitranContext } from '@erudit/shared/bitran/context';
6
- import {
7
- createLinkTarget,
8
- type AbsoluteLinkTarget,
9
- type ExternalLinkTarget,
10
- type LinkTargetType,
11
- type PageLinkTarget,
12
- type UniqueLinkTarget,
13
- } from '@erudit/shared/bitran/link/target';
14
-
15
- const articleContext: BitranContext = {
16
- location: {
17
- type: 'article',
18
- path: 'a/b/c',
19
- },
20
- aliases: {
21
- a1: 'alias1',
22
- },
23
- };
24
-
25
- const contributorContext: BitranContext = {
26
- location: {
27
- type: 'contributor',
28
- path: 'john',
29
- },
30
- aliases: NO_ALIASES(),
31
- };
32
-
33
- //
34
- //
35
- //
36
-
37
- const absoluteTargets = ['/', '/foo/bar/baz'];
38
-
39
- const externalTargets = [
40
- 'http://www.google.com',
41
- 'http://www.google.com/',
42
- 'https://www.google.com/foo/bar/baz',
43
- 'https://www.google.com/foo/bar/baz?a=1&b=2#anchor',
44
- ];
45
-
46
- const validPageTargets: [string, Pick<PageLinkTarget, 'pageType' | 'path'>][] =
47
- [
48
- // With "page|" prefix
49
- ['page|contributor|john', { pageType: 'contributor', path: 'john' }],
50
- ['page|article|foo/bar', { pageType: 'article', path: 'foo/bar' }],
51
- [
52
- 'page|book|combinatorics',
53
- { pageType: 'book', path: 'combinatorics' },
54
- ],
55
- [
56
- 'page|summary',
57
- { pageType: 'summary', path: articleContext.location.path },
58
- ],
59
- // Without "page|" prefix for non-topic parts
60
- ['contributor|john', { pageType: 'contributor', path: 'john' }],
61
- ];
62
-
63
- const invalidPageTargets = [
64
- // Reference topic part in non-topic context
65
- 'page|article',
66
- // Unknown page type
67
- 'page|foo|a/b/c',
68
- // Unkown Bitran location type
69
- 'book|combinatorics',
70
- ];
71
-
72
- const validUniqueTargets: [string, string][] = [
73
- ['definition', 'article|a/b/c|definition'],
74
- ['practice|term', 'practice|a/b/c|term'],
75
- ['contributor|john|theorem', 'contributor|john|theorem'],
76
- ];
77
-
78
- //
79
- //
80
- //
81
-
82
- describe('createLinkTarget', () => {
83
- it.each(absoluteTargets)(
84
- 'should create absolute link target for %p',
85
- (absoluteTarget) => {
86
- const target = createLinkTarget(
87
- absoluteTarget,
88
- articleContext,
89
- ) as AbsoluteLinkTarget;
90
-
91
- expect(target.type).toBe<LinkTargetType>('absolute');
92
- expect(target.href).toBe(absoluteTarget);
93
- },
94
- );
95
-
96
- it.each(externalTargets)(
97
- 'should create external link target for %p',
98
- (externalTarget) => {
99
- const target = createLinkTarget(
100
- externalTarget,
101
- articleContext,
102
- ) as ExternalLinkTarget;
103
-
104
- expect(target.type).toBe<LinkTargetType>('external');
105
- expect(target.href).toBe(externalTarget);
106
- },
107
- );
108
-
109
- for (const [pageTarget, expected] of validPageTargets) {
110
- it(`should create page link target for "${pageTarget}"`, () => {
111
- const target = createLinkTarget(
112
- pageTarget,
113
- articleContext,
114
- ) as PageLinkTarget;
115
-
116
- expect(target.type).toBe<LinkTargetType>('page');
117
- expect(target.pageType).toBe(expected.pageType);
118
- expect(target.path).toBe(expected.path);
119
- });
120
- }
121
-
122
- for (const invalidPageTarget of invalidPageTargets) {
123
- it(`should throw on page link target "${invalidPageTarget}"`, () => {
124
- expect(() =>
125
- createLinkTarget(invalidPageTarget, contributorContext),
126
- ).toThrow();
127
- });
128
- }
129
-
130
- for (const [uniqueTarget, expected] of validUniqueTargets) {
131
- it(`should create unique link target for "${uniqueTarget}"`, () => {
132
- const target = createLinkTarget(
133
- uniqueTarget,
134
- articleContext,
135
- ) as UniqueLinkTarget;
136
-
137
- expect(target.type).toBe<LinkTargetType>('unique');
138
- expect(target.strlocation).toBe(expected);
139
- });
140
- }
141
- });
@@ -1,143 +0,0 @@
1
- import {
2
- decodeBitranLocation,
3
- encodeBitranLocation,
4
- parseBitranLocation,
5
- parsePartialBitranLocation,
6
- stringifyBitranLocation,
7
- type BitranLocation,
8
- } from '@erudit/shared/bitran/location';
9
-
10
- const locations: [BitranLocation, string][] = [
11
- // Full locations
12
- [{ type: 'article', path: 'foo', unique: 'bar' }, 'article|foo|bar'],
13
- [{ type: 'group', path: 'foo', unique: 'bar' }, 'group|foo|bar'],
14
- // Type + path
15
- [{ type: 'article', path: 'foo' }, 'article|foo'],
16
- [{ type: 'group', path: 'foo' }, 'group|foo'],
17
- ];
18
-
19
- const partialLocations: [string, BitranLocation, BitranLocation][] = [
20
- // Full string location
21
- [
22
- 'article|foo/bar|baz',
23
- { type: 'group', path: 'qux' },
24
- { type: 'article', path: 'foo/bar', unique: 'baz' },
25
- ],
26
- // Only unique
27
- [
28
- 'baz',
29
- { type: 'summary', path: 'foo/bar' },
30
- { type: 'summary', path: 'foo/bar', unique: 'baz' },
31
- ],
32
- [
33
- 'baz',
34
- { type: 'contributor', path: 'John' },
35
- { type: 'contributor', path: 'John', unique: 'baz' },
36
- ],
37
- // Topic context
38
- [
39
- 'article|baz',
40
- { type: 'practice', path: 'foo/bar' },
41
- { type: 'article', path: 'foo/bar', unique: 'baz' },
42
- ],
43
- ];
44
-
45
- const invalidPartialLocations: [string, BitranLocation][] = [
46
- // Referencing topic part in non-topic context
47
- ['article|bar', { type: 'contributor', path: 'foo' }],
48
- ];
49
-
50
- const invalidLocations = [
51
- // Too few parts
52
- { type: 'article' },
53
- { path: 'foo' },
54
- { unique: 'foo' },
55
- // Unknown type
56
- { type: 'foo' },
57
- { type: 'foo', path: 'bar', unique: 'baz' },
58
- // Locations that require path
59
- { type: 'article', unique: 'foo' },
60
- { type: 'summary', unique: 'foo' },
61
- { type: 'practice', unique: 'foo' },
62
- { type: 'group', unique: 'foo' },
63
- { type: 'contributor', unique: 'foo' },
64
- ];
65
-
66
- const invalidStrLocations = [
67
- // Too few parts
68
- 'article',
69
- 'group',
70
- // Unknown type
71
- 'foo',
72
- 'foo|bar',
73
- 'foo|bar|baz',
74
- // Empty string unique
75
- 'article|foo/bar|',
76
- ];
77
-
78
- //
79
- //
80
- //
81
-
82
- describe('stringifyBitranLocation', () => {
83
- for (const [location, expected] of locations) {
84
- it(`should produce "${expected}"`, () => {
85
- expect(stringifyBitranLocation(location)).toBe(expected);
86
- });
87
- }
88
-
89
- for (const invalidLocation of invalidLocations) {
90
- it(`should throw on location ${JSON.stringify(invalidLocation)}`, () => {
91
- expect(() =>
92
- stringifyBitranLocation(invalidLocation as BitranLocation),
93
- ).toThrow();
94
- });
95
- }
96
- });
97
-
98
- describe('parseBitranLocation', () => {
99
- for (const [location, expected] of locations) {
100
- it(`should produce ${JSON.stringify(expected)}`, () => {
101
- expect(parseBitranLocation(expected)).toEqual(location);
102
- });
103
- }
104
-
105
- for (const invalidStrLocation of invalidStrLocations) {
106
- it(`should throw on location "${invalidStrLocation}"`, () => {
107
- expect(() => parseBitranLocation(invalidStrLocation)).toThrow();
108
- });
109
- }
110
- });
111
-
112
- describe('parsePartialBitranLocation', () => {
113
- for (const [locationStr, context, expected] of partialLocations) {
114
- it(`should produce ${JSON.stringify(expected)}`, () => {
115
- expect(parsePartialBitranLocation(locationStr, context)).toEqual(
116
- expected,
117
- );
118
- });
119
- }
120
-
121
- for (const [locationStr, context] of invalidPartialLocations) {
122
- it(`should throw on location "${locationStr}"`, () => {
123
- expect(() =>
124
- parsePartialBitranLocation(locationStr, context),
125
- ).toThrow();
126
- });
127
- }
128
- });
129
-
130
- describe('decode/encodeBitranLocation', () => {
131
- it.each([
132
- '',
133
- 'foo',
134
- 'foo|bar',
135
- 'foo|bar|baz',
136
- 'foo|bar/baz|qux',
137
- 'foo|bar/baz/qux|corge:grault:waldo',
138
- ])('should not change string location %p', (testCase) =>
139
- expect(decodeBitranLocation(encodeBitranLocation(testCase))).toBe(
140
- testCase,
141
- ),
142
- );
143
- });