@thecodeblogs/blog 0.20.0 → 0.20.2
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.
|
@@ -5,7 +5,6 @@ import * as i1 from '@angular/common/http';
|
|
|
5
5
|
import { HttpParams } from '@angular/common/http';
|
|
6
6
|
import { map, debounceTime } from 'rxjs/operators';
|
|
7
7
|
import { Subject, of, Subscription } from 'rxjs';
|
|
8
|
-
import { Utility } from '@blog/services/utility';
|
|
9
8
|
import * as i6 from '@angular/common';
|
|
10
9
|
import { isPlatformBrowser, NgIf, CommonModule } from '@angular/common';
|
|
11
10
|
import * as i2 from 'ngx-device-detector';
|
|
@@ -266,6 +265,167 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.3", ngImpor
|
|
|
266
265
|
}]
|
|
267
266
|
}], ctorParameters: () => [{ type: i1.HttpClient }] });
|
|
268
267
|
|
|
268
|
+
class Utility {
|
|
269
|
+
static replaceNbsps(str) {
|
|
270
|
+
var re = new RegExp(String.fromCharCode(160), "g");
|
|
271
|
+
return str.replace(re, " ");
|
|
272
|
+
}
|
|
273
|
+
static convertHTMLToType(el) {
|
|
274
|
+
var value = "";
|
|
275
|
+
var contentType = "";
|
|
276
|
+
// First test for custom objects
|
|
277
|
+
var testValue = el.innerText;
|
|
278
|
+
try {
|
|
279
|
+
var obj = JSON.parse(testValue);
|
|
280
|
+
return obj;
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
//console.error(error);
|
|
284
|
+
}
|
|
285
|
+
//console.log(el.tagName);
|
|
286
|
+
switch (el.tagName.toLowerCase()) {
|
|
287
|
+
case "p":
|
|
288
|
+
if (el.children.length > 0) {
|
|
289
|
+
var child = el.children[0];
|
|
290
|
+
if (child.tagName.toLowerCase() === "a") {
|
|
291
|
+
var c = new Content();
|
|
292
|
+
value = child.href;
|
|
293
|
+
c.value = value;
|
|
294
|
+
c.title = Utility.replaceNbsps(child.innerText);
|
|
295
|
+
c.type = ContentType.URL;
|
|
296
|
+
return c;
|
|
297
|
+
}
|
|
298
|
+
else if (child.tagName.toLowerCase() === 'img') {
|
|
299
|
+
var c = new Content();
|
|
300
|
+
value = child.src;
|
|
301
|
+
c.value = value;
|
|
302
|
+
c.type = ContentType.IMAGE;
|
|
303
|
+
return c;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
var c = new Content();
|
|
308
|
+
value = Utility.replaceNbsps(el.innerText);
|
|
309
|
+
c.value = value;
|
|
310
|
+
c.type = ContentType.TEXT;
|
|
311
|
+
return c;
|
|
312
|
+
}
|
|
313
|
+
break;
|
|
314
|
+
case "a":
|
|
315
|
+
var c = new Content();
|
|
316
|
+
value = el.href;
|
|
317
|
+
c.value = value;
|
|
318
|
+
c.title = Utility.replaceNbsps(el.innerText);
|
|
319
|
+
c.type = ContentType.URL;
|
|
320
|
+
return c;
|
|
321
|
+
break;
|
|
322
|
+
case "h4":
|
|
323
|
+
var s = new Section();
|
|
324
|
+
value = Utility.replaceNbsps(el.innerText);
|
|
325
|
+
s.subheading = Utility.replaceNbsps(value);
|
|
326
|
+
return s;
|
|
327
|
+
break;
|
|
328
|
+
case "blockquote":
|
|
329
|
+
var c = new Content();
|
|
330
|
+
value = el.innerHTML;
|
|
331
|
+
c.value = "<blockquote>" + value + "</blockquote>";
|
|
332
|
+
c.type = ContentType.HTML;
|
|
333
|
+
return c;
|
|
334
|
+
break;
|
|
335
|
+
default:
|
|
336
|
+
var c = new Content();
|
|
337
|
+
value = el.innerHTML;
|
|
338
|
+
c.value = value;
|
|
339
|
+
c.type = ContentType.HTML;
|
|
340
|
+
return c;
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
static convertHtmlToBlogFormat(entry, html) {
|
|
345
|
+
entry.sections = [];
|
|
346
|
+
var newEntry = new Entry(entry);
|
|
347
|
+
var el = document.createElement('html');
|
|
348
|
+
el.innerHTML = html;
|
|
349
|
+
// Creating the HTML element adds a head and body
|
|
350
|
+
// We hardcode to 1 to reference the body, and its
|
|
351
|
+
// child elements
|
|
352
|
+
var children = el.children[1].children;
|
|
353
|
+
;
|
|
354
|
+
var section = new Section();
|
|
355
|
+
section.subheading = "";
|
|
356
|
+
for (let i = 0; i < children.length; i++) {
|
|
357
|
+
var child = children[i];
|
|
358
|
+
var thing = Utility.convertHTMLToType(child);
|
|
359
|
+
//console.log('Thing: ' + JSON.stringify(thing));
|
|
360
|
+
//console.log('Typeof: ' + JSON.stringify(typeof(thing)));
|
|
361
|
+
if (thing instanceof Section) {
|
|
362
|
+
section = thing;
|
|
363
|
+
section.order = i * 10;
|
|
364
|
+
entry.sections.push(section);
|
|
365
|
+
}
|
|
366
|
+
else if (thing instanceof Content) {
|
|
367
|
+
if (entry.sections.length === 0) {
|
|
368
|
+
thing.order = i * 10;
|
|
369
|
+
section.contents.push(thing);
|
|
370
|
+
entry.sections.push(section);
|
|
371
|
+
section.order = i * 10;
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
thing.order = i * 10;
|
|
375
|
+
section.contents.push(thing);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
if (thing !== null && typeof (thing) !== 'undefined') {
|
|
380
|
+
thing.order = i * 10;
|
|
381
|
+
section.contents.push(thing);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
//console.log('E: ' + JSON.stringify(entry));
|
|
386
|
+
return entry;
|
|
387
|
+
}
|
|
388
|
+
static convertTypeToHTML(content) {
|
|
389
|
+
switch (content.type) {
|
|
390
|
+
case ContentType.CODE:
|
|
391
|
+
return '<pre><code class="language-ts">' + content?.value + '</code></pre>';
|
|
392
|
+
break;
|
|
393
|
+
case ContentType.IMAGE:
|
|
394
|
+
return '<img src="' + content?.value + '"/>';
|
|
395
|
+
break;
|
|
396
|
+
case ContentType.MEDIA:
|
|
397
|
+
return '<pre>' + JSON.stringify(content) + '</pre>';
|
|
398
|
+
break;
|
|
399
|
+
case ContentType.HTML:
|
|
400
|
+
return content.value;
|
|
401
|
+
break;
|
|
402
|
+
case ContentType.URL:
|
|
403
|
+
return '<a target="_blank" href="' + content.value + '">' + content.title + '</a><br>';
|
|
404
|
+
break;
|
|
405
|
+
case ContentType.TEXT:
|
|
406
|
+
return '<p>' + content.value + '</p>';
|
|
407
|
+
break;
|
|
408
|
+
default:
|
|
409
|
+
return '<pre>' + JSON.stringify(content) + '</pre>';
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
static convertBlogToHtml(blog) {
|
|
414
|
+
var html = "";
|
|
415
|
+
var sections = blog.sections;
|
|
416
|
+
for (var i = 0; i < sections.length; i++) {
|
|
417
|
+
var section = sections[i];
|
|
418
|
+
html = html + '<h4>' + section.subheading + '</h4>';
|
|
419
|
+
var contents = section.contents;
|
|
420
|
+
for (var j = 0; j < contents.length; j++) {
|
|
421
|
+
var content = contents[j];
|
|
422
|
+
html = html + Utility.convertTypeToHTML(content);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return html;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
269
429
|
class EntryService extends DjangoRestFrameworkEndpointService {
|
|
270
430
|
handleResponse(obj) {
|
|
271
431
|
return new Entry(obj);
|
|
@@ -2072,5 +2232,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.3", ngImpor
|
|
|
2072
2232
|
* Generated bundle index. Do not edit.
|
|
2073
2233
|
*/
|
|
2074
2234
|
|
|
2075
|
-
export { Base, CommentService, Content, ContentType, CoreEvent, CoreEventType, CoreModule, DjangoRestFrameworkEndpointService, Entry, EntryCreatorComponent, EntryRendererComponent, EntryRendererWrapperComponent, EntrySelectorDialogComponent, EntryService, EntrySummaryComponent, Guid, IdentityService, Interaction, InteractionService, JsonRendererComponent, LandingPageComponent, LinkyPipe, ListResponse, MainComponent, MediaUploadModalComponent, OutlineViewComponent, PrismService, Routes, Section, SideNavigationComponent, StaticHtmlComponent, StaticHtmlService, TagService, TimeAgoPipe, Upload, UploadService, View, ViewService, VisitorProfile, VisitorProfileService };
|
|
2235
|
+
export { Base, CommentService, Content, ContentType, CoreEvent, CoreEventType, CoreModule, DjangoRestFrameworkEndpointService, Entry, EntryCreatorComponent, EntryRendererComponent, EntryRendererWrapperComponent, EntrySelectorDialogComponent, EntryService, EntrySummaryComponent, Guid, IdentityService, Interaction, InteractionService, JsonRendererComponent, LandingPageComponent, LinkyPipe, ListResponse, MainComponent, MediaUploadModalComponent, OutlineViewComponent, PrismService, Routes, Section, SideNavigationComponent, StaticHtmlComponent, StaticHtmlService, TagService, TimeAgoPipe, Upload, UploadService, Utility, View, ViewService, VisitorProfile, VisitorProfileService };
|
|
2076
2236
|
//# sourceMappingURL=thecodeblogs-blog.mjs.map
|