-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthors.js
More file actions
111 lines (98 loc) · 3.1 KB
/
authors.js
File metadata and controls
111 lines (98 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// authors.js — author profiles + follow helpers
(() => {
const DEFAULT_AVATAR = 'icon.svg';
// Extend this list whenever you add new authors.
const AUTHORS = [
{
id: 'syntax_syndicate',
name: 'Syntax_Syndicate',
role: 'Команда',
avatar: 'icon.svg',
bio: 'Команда/проект, который собирает и оформляет базу знаний. Публикуем материалы, делаем поиск, граф, офлайн и PWA.',
links: { site: 'index.html' },
},
{
id: 'uncledeny',
name: 'UncleDeniy',
role: 'DevOps / Security',
avatar: 'icon.svg',
bio: 'Практик DevOps и сетевой безопасности. Пишу прикладные лекции: диагностика, трафик, протоколы, Kubernetes и blue-team workflow.',
links: { site: 'index.html' },
}
];
function slugify(name) {
return (name || '')
.toString()
.trim()
.toLowerCase()
.replace(/[_\s]+/g, '-')
.replace(/[^a-z0-9\-а-яё]/gi, '')
.replace(/\-+/g, '-')
.replace(/^\-+|\-+$/g, '')
.slice(0, 64) || 'author';
}
function getAuthorId(name) {
// Known mapping first
const exact = AUTHORS.find(a => a.name === name);
if (exact) return exact.id;
// Fallback
return slugify(name);
}
function getAuthor(authorName) {
const id = getAuthorId(authorName);
const found = AUTHORS.find(a => a.id === id) || AUTHORS.find(a => a.name === authorName);
if (found) return found;
// Auto-generate profile for unknown authors.
return {
id,
name: authorName || 'Автор',
role: 'Автор',
avatar: DEFAULT_AVATAR,
bio: 'Автор материалов на сайте. Добавь в избранное, чтобы получать уведомления о новых публикациях.',
links: {},
};
}
// Favorites (follow)
const LS_FAV = 'aa:favAuthors';
function readFavs() {
try {
const raw = localStorage.getItem(LS_FAV);
const v = raw ? JSON.parse(raw) : [];
return Array.isArray(v) ? v : [];
} catch {
return [];
}
}
function writeFavs(list) {
try { localStorage.setItem(LS_FAV, JSON.stringify(list)); } catch {}
}
function isFav(authorId) {
return readFavs().includes(authorId);
}
function toggleFav(authorId) {
const list = readFavs();
const i = list.indexOf(authorId);
if (i >= 0) list.splice(i, 1);
else list.push(authorId);
writeFavs(list);
return list;
}
// Expose to window
window.Authors = {
AUTHORS,
getAuthorId,
getAuthor,
readFavs,
writeFavs,
isFav,
toggleFav,
};
// Backward/compat helpers (used by layout.js and older code)
window.getAuthorId = window.getAuthorId || getAuthorId;
window.getAuthorProfile = window.getAuthorProfile || ((name) => getAuthor(name));
// Helpful extra
window.getAuthorById = window.getAuthorById || ((id) => {
const found = AUTHORS.find(a => a.id === id);
return found || getAuthor(id);
});
})();