なごみ commited on
Commit
d394c2a
·
unverified ·
2 Parent(s): 68866be988ecc7

Merge pull request #25 from nagomi-sugarheart/claude/implement-claude-7-1-S4nXe

Browse files
Files changed (2) hide show
  1. main.py +11 -1
  2. templates/admin_editor.html +13 -8
main.py CHANGED
@@ -284,10 +284,16 @@ async def index(request: Request, id: str = None, page: int = 0,
284
  {"article": None, "comments": []})
285
  comments = get_comments(id)
286
  base_url = SPACE_URL or str(request.base_url).rstrip("/")
 
 
 
 
 
 
287
  return templates.TemplateResponse(request, "blog_detail.html", {
288
  "article": article,
289
  "comments": comments,
290
- "content": clean_html(get_content(article)),
291
  "tags": get_tags(article),
292
  "space_url": base_url,
293
  })
@@ -515,6 +521,8 @@ async def api_ai_decorate(request: Request):
515
  f"現在のHTMLコードを、以下の指示に基づいて修正してください。\n"
516
  f"本文の内容は絶対に変更せず、HTMLタグやスタイルのみを変更すること。\n"
517
  f"CSSは必ずインラインスタイル(style属性)のみで記述し、<style>タグやclassは使用しないこと。\n"
 
 
518
  f"出力は純粋なHTMLコードのみを返してください。\n"
519
  f"【現在のHTML】{html_content}\n"
520
  f"【修正指示】{instruction}"
@@ -549,6 +557,8 @@ async def api_ai_decorate_all(request: Request):
549
  f"全ブロックを通じて統一されたデザイン・スタイルになるよう、以下の指示に基づいてHTMLを修正してください。\n"
550
  f"本文の内容は絶対に変更せず、HTMLタグやスタイルのみを変更すること。\n"
551
  f"CSSは必ずインラインスタイル(style属性)のみで記述し、<style>タグやclassは使用しないこと。\n"
 
 
552
  f"出力は同じJSON形式(idとhtmlのペアの配列)のみを返してください。余分なテキストや説明は不要です。\n"
553
  f"【ブロックデータ(JSON)】\n{blocks_json_str}\n"
554
  f"【装飾指示】{instruction}\n"
 
284
  {"article": None, "comments": []})
285
  comments = get_comments(id)
286
  base_url = SPACE_URL or str(request.base_url).rstrip("/")
287
+ # contentBlocks が存在する場合はブロックから直接レンダリングし
288
+ # microCMS の contentRich フィールドによるスタイル除去を回避する
289
+ if article.get("contentBlocks"):
290
+ rendered_content = render_blocks_to_html(blocks_from_article(article))
291
+ else:
292
+ rendered_content = clean_html(get_content(article))
293
  return templates.TemplateResponse(request, "blog_detail.html", {
294
  "article": article,
295
  "comments": comments,
296
+ "content": rendered_content,
297
  "tags": get_tags(article),
298
  "space_url": base_url,
299
  })
 
521
  f"現在のHTMLコードを、以下の指示に基づいて修正してください。\n"
522
  f"本文の内容は絶対に変更せず、HTMLタグやスタイルのみを変更すること。\n"
523
  f"CSSは必ずインラインスタイル(style属性)のみで記述し、<style>タグやclassは使用しないこと。\n"
524
+ f"ダークモード対応のため、テキストの文字色には black/white などの固定色を使わず必ず color: inherit を使うこと。"
525
+ f"背景にグレー系の色を使う場合は rgba(128,128,128,0.1) などの半透過色を使うこと。\n"
526
  f"出力は純粋なHTMLコードのみを返してください。\n"
527
  f"【現在のHTML】{html_content}\n"
528
  f"【修正指示】{instruction}"
 
557
  f"全ブロックを通じて統一されたデザイン・スタイルになるよう、以下の指示に基づいてHTMLを修正してください。\n"
558
  f"本文の内容は絶対に変更せず、HTMLタグやスタイルのみを変更すること。\n"
559
  f"CSSは必ずインラインスタイル(style属性)のみで記述し、<style>タグやclassは使用しないこと。\n"
560
+ f"ダークモード対応のため、テキストの文字色には black/white などの固定色を使わず必ず color: inherit を使うこと。"
561
+ f"背景にグレー系の色を使う場合は rgba(128,128,128,0.1) などの半透過色を使うこと。\n"
562
  f"出力は同じJSON形式(idとhtmlのペアの配列)のみを返してください。余分なテキストや説明は不要です。\n"
563
  f"【ブロックデータ(JSON)】\n{blocks_json_str}\n"
564
  f"【装飾指示】{instruction}\n"
templates/admin_editor.html CHANGED
@@ -208,6 +208,7 @@
208
  <button onclick="tb('ul')" title="箇条書き" class="w-8 h-8 flex items-center justify-center border dark:border-gray-600 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-200"><i class="fas fa-list-ul text-sm"></i></button>
209
  <button onclick="tb('p')" title="段落" class="w-8 h-8 flex items-center justify-center border dark:border-gray-600 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-200"><i class="fas fa-paragraph text-sm"></i></button>
210
  <button onclick="tb('link')" title="リンク" class="w-8 h-8 flex items-center justify-center border dark:border-gray-600 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-200"><i class="fas fa-link text-sm"></i></button>
 
211
  <button onclick="insertEmbed('youtube')" title="YouTube埋め込み" class="w-8 h-8 flex items-center justify-center border dark:border-gray-600 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-200"><i class="fab fa-youtube text-sm"></i></button>
212
  <button onclick="insertEmbed('twitter')" title="X(Twitter)埋め込み" class="w-8 h-8 flex items-center justify-center border dark:border-gray-600 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-xs font-bold text-gray-700 dark:text-gray-200">𝕏</button>
213
  <div class="h-8 w-px bg-gray-200 dark:bg-gray-600 mx-1"></div>
@@ -490,7 +491,7 @@ function deleteBlock(idx) {
490
  function addBlock(idx, type) {
491
  const id = 'block-' + Math.random().toString(36).substr(2, 8);
492
  const nb = type === 'text'
493
- ? {type:'text', id, html:''}
494
  : {type:'image', id, url:'', alt:'', maxWidth:900};
495
  blocks.splice(idx, 0, nb);
496
  renderBlocks();
@@ -516,22 +517,23 @@ if (window.visualViewport) {
516
 
517
  function openEditor(idx) {
518
  currentEditIdx = idx;
519
- const html = blocks[idx].html || '';
520
- setEditorContent(html);
 
 
 
 
521
  tempContent = html;
522
  document.getElementById('editor-modal').classList.add('active');
523
  document.body.style.overflow = 'hidden';
524
  syncModalToViewport();
525
- if (editorMode === 'rich') {
526
- initQuill();
527
- setTimeout(() => { if (quill) quill.root.innerHTML = html; updatePreview(); }, 50);
528
- }
529
- updatePreview();
530
  }
531
 
532
  function closeEditor(save) {
533
  if (save && currentEditIdx !== null) {
534
  blocks[currentEditIdx].html = getEditorContent();
 
535
  }
536
  currentEditIdx = null;
537
  const modal = document.getElementById('editor-modal');
@@ -567,6 +569,9 @@ function tb(type) {
567
  else if (type === 'h3') { full = `<h3>${sel || '見出し'}</h3>`; }
568
  else if (type === 'p') { full = `<p>${sel || 'テキスト'}</p>`; }
569
  else if (type === 'ul') { full = `<ul>\n <li>${sel || '項目'}</li>\n</ul>`; }
 
 
 
570
  else if (type === 'link') {
571
  const href = prompt('URLを入力:');
572
  if (href) full = `<a href="${href}">${sel || href}</a>`;
 
208
  <button onclick="tb('ul')" title="箇条書き" class="w-8 h-8 flex items-center justify-center border dark:border-gray-600 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-200"><i class="fas fa-list-ul text-sm"></i></button>
209
  <button onclick="tb('p')" title="段落" class="w-8 h-8 flex items-center justify-center border dark:border-gray-600 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-200"><i class="fas fa-paragraph text-sm"></i></button>
210
  <button onclick="tb('link')" title="リンク" class="w-8 h-8 flex items-center justify-center border dark:border-gray-600 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-200"><i class="fas fa-link text-sm"></i></button>
211
+ <button onclick="tb('blockquote')" title="引用" class="w-8 h-8 flex items-center justify-center border dark:border-gray-600 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-200"><i class="fas fa-quote-left text-sm"></i></button>
212
  <button onclick="insertEmbed('youtube')" title="YouTube埋め込み" class="w-8 h-8 flex items-center justify-center border dark:border-gray-600 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-200"><i class="fab fa-youtube text-sm"></i></button>
213
  <button onclick="insertEmbed('twitter')" title="X(Twitter)埋め込み" class="w-8 h-8 flex items-center justify-center border dark:border-gray-600 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-xs font-bold text-gray-700 dark:text-gray-200">𝕏</button>
214
  <div class="h-8 w-px bg-gray-200 dark:bg-gray-600 mx-1"></div>
 
491
  function addBlock(idx, type) {
492
  const id = 'block-' + Math.random().toString(36).substr(2, 8);
493
  const nb = type === 'text'
494
+ ? {type:'text', id, html:'', editorMode:'rich'}
495
  : {type:'image', id, url:'', alt:'', maxWidth:900};
496
  blocks.splice(idx, 0, nb);
497
  renderBlocks();
 
517
 
518
  function openEditor(idx) {
519
  currentEditIdx = idx;
520
+ const block = blocks[idx];
521
+ const html = block.html || '';
522
+ const blockMode = block.editorMode || 'rich';
523
+ // 両エディタに内容をセットしてからモードを切り替える
524
+ document.getElementById('modal-textarea').value = html;
525
+ if (quill) quill.root.innerHTML = html;
526
  tempContent = html;
527
  document.getElementById('editor-modal').classList.add('active');
528
  document.body.style.overflow = 'hidden';
529
  syncModalToViewport();
530
+ setEditorMode(blockMode);
 
 
 
 
531
  }
532
 
533
  function closeEditor(save) {
534
  if (save && currentEditIdx !== null) {
535
  blocks[currentEditIdx].html = getEditorContent();
536
+ blocks[currentEditIdx].editorMode = editorMode;
537
  }
538
  currentEditIdx = null;
539
  const modal = document.getElementById('editor-modal');
 
569
  else if (type === 'h3') { full = `<h3>${sel || '見出し'}</h3>`; }
570
  else if (type === 'p') { full = `<p>${sel || 'テキスト'}</p>`; }
571
  else if (type === 'ul') { full = `<ul>\n <li>${sel || '項目'}</li>\n</ul>`; }
572
+ else if (type === 'blockquote') {
573
+ full = `<blockquote style="background-color:rgba(128,128,128,0.1);border-left:5px solid #e07297;padding:15px 20px;margin:25px 0;border-radius:5px;color:inherit;">${sel || '引用テキスト'}</blockquote>`;
574
+ }
575
  else if (type === 'link') {
576
  const href = prompt('URLを入力:');
577
  if (href) full = `<a href="${href}">${sel || href}</a>`;