tfrere HF Staff commited on
Commit
d8c3c68
·
1 Parent(s): d63dcfe

feat(login-page): align with app design tokens, bigger outlined HF button

Browse files

- Extract a single renderLoginPage() helper used by both the editor login
gate and the published-article fallback (no more duplicated inline HTML)
- Use the app's primary color (OKLCH) and Source Sans Pro font, with proper
light/dark via prefers-color-scheme so the page no longer looks like an
unrelated dark stub
- Replace the small filled button with a bigger outlined CTA (14×22 px
padding, 1.5px primary border, color-mix hover)
- Inline the official Hugging Face brand logo SVG (no external network
dependency, no emoji fallback)
- Escape user-controlled hint substitutions through a dedicated escapeHtml()

Made-with: Cursor

Files changed (1) hide show
  1. backend/src/create-app.ts +157 -29
backend/src/create-app.ts CHANGED
@@ -20,34 +20,166 @@ export { debouncedSave, resetSaveTimers, resetPublishedRestored } from "./persis
20
 
21
  const DEFAULT_DOC_NAME = "default";
22
 
23
- function sendLoginPage(res: express.Response) {
24
- res.status(200).send(`<!DOCTYPE html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  <html lang="en">
26
  <head>
27
  <meta charset="utf-8" />
28
  <meta name="viewport" content="width=device-width, initial-scale=1" />
29
- <title>Research Article Template Editor</title>
30
  <style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  * { margin: 0; padding: 0; box-sizing: border-box; }
32
- body { display: flex; align-items: center; justify-content: center; height: 100vh;
33
- font-family: system-ui, -apple-system, sans-serif; background: #0a0a0a; color: #aaa; }
34
- .card { text-align: center; max-width: 420px; padding: 2rem; }
35
- h1 { color: #fff; font-size: 1.5rem; margin-bottom: 0.5rem; }
36
- p { margin-bottom: 1.5rem; line-height: 1.5; }
37
- a.btn { display: inline-block; padding: 0.6rem 1.5rem; border-radius: 8px;
38
- background: #958DF1; color: #fff; text-decoration: none; font-weight: 500;
39
- transition: opacity 0.15s; }
40
- a.btn:hover { opacity: 0.85; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  </style>
42
  </head>
43
  <body>
44
- <div class="card">
45
- <h1>This article is not yet published</h1>
46
- <p>Log in with your Hugging Face account to access the editor.</p>
47
- <a class="btn" href="/oauth/authorize" target="_blank">Sign in with Hugging Face</a>
48
- </div>
 
 
 
 
49
  </body>
50
- </html>`);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  }
52
 
53
  export function createApp() {
@@ -178,17 +310,13 @@ export function createApp() {
178
  const user = await resolveUser(token);
179
 
180
  if (!user || !user.canEdit) {
181
- res.status(200).send(`<!DOCTYPE html>
182
- <html lang="en">
183
- <head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/>
184
- <title>Sign in required</title>
185
- <style>*{margin:0;padding:0;box-sizing:border-box}body{display:flex;align-items:center;justify-content:center;height:100vh;font-family:system-ui,-apple-system,sans-serif;background:#0a0a0a;color:#aaa}.card{text-align:center;max-width:420px;padding:2rem}h1{color:#fff;font-size:1.5rem;margin-bottom:.5rem}p{margin-bottom:1.5rem;line-height:1.5}a.btn{display:inline-block;padding:.6rem 1.5rem;border-radius:8px;background:#958DF1;color:#fff;text-decoration:none;font-weight:500;transition:opacity .15s}a.btn:hover{opacity:.85}</style></head>
186
- <body><div class="card">
187
- <h1>Editor access</h1>
188
- <p>Sign in with your Hugging Face account to start editing.</p>
189
- <a class="btn" href="/oauth/authorize" target="_blank">Sign in with Hugging Face</a>
190
- <p style="margin-top:1rem;font-size:.85rem;color:#666">After signing in, come back and <a href="/editor" style="color:#958DF1">refresh this page</a>.</p>
191
- </div></body></html>`);
192
  return;
193
  }
194
  }
 
20
 
21
  const DEFAULT_DOC_NAME = "default";
22
 
23
+ /**
24
+ * Inline SVG of the official Hugging Face brand logo (the smiling face).
25
+ * Source: https://huggingface.co/front/assets/huggingface_logo-noborder.svg
26
+ */
27
+ const HF_LOGO_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 95 88" width="28" height="26" aria-hidden="true" focusable="false">
28
+ <path fill="#FFD21E" d="M47.21 76.5a34.75 34.75 0 1 0 0-69.5 34.75 34.75 0 0 0 0 69.5Z"/>
29
+ <path fill="#FF9D0B" d="M81.96 41.75a34.75 34.75 0 1 0-69.5 0 34.75 34.75 0 0 0 69.5 0Zm-73.5 0a38.75 38.75 0 1 1 77.5 0 38.75 38.75 0 0 1-77.5 0Z"/>
30
+ <path fill="#3A3B45" d="M58.5 32.3c1.28.44 1.78 3.06 3.07 2.38a5 5 0 1 0-6.76-2.07c.61 1.15 2.55-.72 3.7-.32ZM34.95 32.3c-1.28.44-1.79 3.06-3.07 2.38a5 5 0 1 1 6.76-2.07c-.61 1.15-2.56-.72-3.7-.32Z"/>
31
+ <path fill="#FF323D" d="M46.96 56.29c9.83 0 13-8.76 13-13.26 0-2.34-1.57-1.6-4.09-.36-2.33 1.15-5.46 2.74-8.9 2.74-7.19 0-13-6.88-13-2.38s3.16 13.26 13 13.26Z"/>
32
+ <path fill="#3A3B45" fill-rule="evenodd" d="M39.43 54a8.7 8.7 0 0 1 5.3-4.49c.4-.12.81.57 1.24 1.28.4.68.82 1.37 1.24 1.37.45 0 .9-.68 1.33-1.35.45-.7.89-1.38 1.32-1.25a8.61 8.61 0 0 1 5 4.17c3.73-2.94 5.1-7.74 5.1-10.7 0-2.34-1.57-1.6-4.09-.36l-.14.07c-2.31 1.15-5.39 2.67-8.77 2.67s-6.45-1.52-8.77-2.67c-2.6-1.29-4.23-2.1-4.23.29 0 3.05 1.46 8.06 5.47 10.97Z" clip-rule="evenodd"/>
33
+ <path fill="#FF9D0B" d="M70.71 37a3.25 3.25 0 1 0 0-6.5 3.25 3.25 0 0 0 0 6.5ZM24.21 37a3.25 3.25 0 1 0 0-6.5 3.25 3.25 0 0 0 0 6.5Z"/>
34
+ </svg>`;
35
+
36
+ interface LoginPageOptions {
37
+ title: string;
38
+ description: string;
39
+ /** Optional secondary line shown below the button (e.g. "after signing in, refresh"). */
40
+ hint?: string;
41
+ }
42
+
43
+ function renderLoginPage({ title, description, hint }: LoginPageOptions): string {
44
+ const safeTitle = escapeHtml(title);
45
+ const safeDescription = escapeHtml(description);
46
+ const hintHtml = hint
47
+ ? `<p class="login__hint">${escapeHtml(hint).replace(
48
+ /\{refresh\}/g,
49
+ `<a class="login__hint-link" href="/editor">refresh this page</a>`,
50
+ )}</p>`
51
+ : "";
52
+
53
+ return `<!DOCTYPE html>
54
  <html lang="en">
55
  <head>
56
  <meta charset="utf-8" />
57
  <meta name="viewport" content="width=device-width, initial-scale=1" />
58
+ <title>${safeTitle} - Research Article Template Editor</title>
59
  <style>
60
+ :root {
61
+ --primary-color: oklch(0.75 0.12 47);
62
+ --primary-color-hover: oklch(from var(--primary-color) calc(l - 0.05) c h);
63
+ --page-bg: #ffffff;
64
+ --text-color: rgba(0, 0, 0, .85);
65
+ --muted-color: rgba(0, 0, 0, .6);
66
+ --border-color: rgba(0, 0, 0, .15);
67
+ --button-radius: 6px;
68
+ --font-stack: "Source Sans Pro", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
69
+ }
70
+ @media (prefers-color-scheme: dark) {
71
+ :root {
72
+ --page-bg: #0f1115;
73
+ --text-color: rgba(255, 255, 255, .9);
74
+ --muted-color: rgba(255, 255, 255, .65);
75
+ --border-color: rgba(255, 255, 255, .18);
76
+ }
77
+ }
78
  * { margin: 0; padding: 0; box-sizing: border-box; }
79
+ html, body { height: 100%; }
80
+ body {
81
+ display: flex;
82
+ align-items: center;
83
+ justify-content: center;
84
+ padding: 24px;
85
+ font-family: var(--font-stack);
86
+ background: var(--page-bg);
87
+ color: var(--text-color);
88
+ -webkit-font-smoothing: antialiased;
89
+ }
90
+ .login {
91
+ text-align: center;
92
+ max-width: 460px;
93
+ width: 100%;
94
+ }
95
+ .login__title {
96
+ font-size: 1.625rem;
97
+ font-weight: 600;
98
+ letter-spacing: -0.01em;
99
+ margin-bottom: 0.5rem;
100
+ }
101
+ .login__description {
102
+ font-size: 1rem;
103
+ line-height: 1.55;
104
+ color: var(--muted-color);
105
+ margin-bottom: 2rem;
106
+ }
107
+ .login__btn {
108
+ display: inline-flex;
109
+ align-items: center;
110
+ gap: 12px;
111
+ padding: 14px 22px;
112
+ font-family: inherit;
113
+ font-size: 1rem;
114
+ font-weight: 600;
115
+ color: var(--text-color);
116
+ background: transparent;
117
+ border: 1.5px solid var(--primary-color);
118
+ border-radius: var(--button-radius);
119
+ text-decoration: none;
120
+ cursor: pointer;
121
+ transition: background-color 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
122
+ }
123
+ .login__btn:hover {
124
+ background: color-mix(in srgb, var(--primary-color) 12%, transparent);
125
+ border-color: var(--primary-color-hover);
126
+ }
127
+ .login__btn:active {
128
+ transform: translateY(1px);
129
+ }
130
+ .login__btn:focus-visible {
131
+ outline: 2px solid var(--primary-color);
132
+ outline-offset: 3px;
133
+ }
134
+ .login__btn svg {
135
+ flex-shrink: 0;
136
+ display: block;
137
+ }
138
+ .login__hint {
139
+ margin-top: 1.25rem;
140
+ font-size: 0.9rem;
141
+ color: var(--muted-color);
142
+ }
143
+ .login__hint-link {
144
+ color: var(--primary-color);
145
+ text-decoration: none;
146
+ border-bottom: 1px dashed color-mix(in srgb, var(--primary-color) 50%, transparent);
147
+ }
148
+ .login__hint-link:hover {
149
+ border-bottom-style: solid;
150
+ }
151
  </style>
152
  </head>
153
  <body>
154
+ <main class="login">
155
+ <h1 class="login__title">${safeTitle}</h1>
156
+ <p class="login__description">${safeDescription}</p>
157
+ <a class="login__btn" href="/oauth/authorize" target="_blank" rel="noopener">
158
+ ${HF_LOGO_SVG}
159
+ <span>Sign in with Hugging Face</span>
160
+ </a>
161
+ ${hintHtml}
162
+ </main>
163
  </body>
164
+ </html>`;
165
+ }
166
+
167
+ function escapeHtml(value: string): string {
168
+ return value
169
+ .replace(/&/g, "&amp;")
170
+ .replace(/</g, "&lt;")
171
+ .replace(/>/g, "&gt;")
172
+ .replace(/"/g, "&quot;")
173
+ .replace(/'/g, "&#39;");
174
+ }
175
+
176
+ function sendLoginPage(res: express.Response) {
177
+ res.status(200).send(
178
+ renderLoginPage({
179
+ title: "This article is not yet published",
180
+ description: "Log in with your Hugging Face account to access the editor.",
181
+ }),
182
+ );
183
  }
184
 
185
  export function createApp() {
 
310
  const user = await resolveUser(token);
311
 
312
  if (!user || !user.canEdit) {
313
+ res.status(200).send(
314
+ renderLoginPage({
315
+ title: "Editor access",
316
+ description: "Sign in with your Hugging Face account to start editing.",
317
+ hint: "After signing in, come back and {refresh}.",
318
+ }),
319
+ );
 
 
 
 
320
  return;
321
  }
322
  }