All files / src/layouts Layout.astro

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
---
import Navbar from '../components/Navbar/index.tsx';
import Footer from '../components/Footer/index.tsx';
import '../styles/global.scss';
import config from '../config/index.json';
 
interface Props {
  title?: string;
  description?: string;
  ogImage?: string;
  ogpPath?: string;
  isPostPage?: boolean;
  canonicalUrl?: string;
  isPost?: boolean;
  tag?: string;
  noindex?: boolean;
  datePublished?: string;
  dateModified?: string;
  author?: string;
  keywords?: string[];
  faq?: { question: string; answer: string }[];
  wordCount?: number;
}
 
const {
  title = config.siteTitle,
  description = config.description,
  ogImage = config.defaultImage,
  ogpPath,
  isPostPage = false,
  canonicalUrl,
  isPost = false,
  tag = '',
  noindex = false,
  datePublished,
  dateModified,
  author = config.author,
  keywords = [],
  faq = [],
  wordCount,
} = Astro.props;
 
const siteTitle = config.siteTitle;
const url = canonicalUrl || `${config.siteUrl}${Astro.url.pathname}`;
const pageTitle = title === siteTitle ? title : `${title} | ${siteTitle}`;
const ogpImageLink = ogpPath
  ? `${config.siteUrl}${ogpPath}`
  : `${config.siteUrl}/og/index.png`;
 
const japaneseKeywords = ['技術ブログ', 'プログラミング', '開発', 'エンジニアリング'];
const allKeywords = [...keywords, ...japaneseKeywords, tag].filter(Boolean).join(', ');
 
// Schema.org JSON-LD
const schemaOrgList: object[] = [];
 
// WebSite schema
schemaOrgList.push({
  '@context': 'https://schema.org',
  '@type': 'WebSite',
  '@id': `${config.siteUrl}/#website`,
  url: `${config.siteUrl}/`,
  name: config.siteTitle,
  description: config.description,
  publisher: { '@id': `${config.siteUrl}/#person` },
  inLanguage: 'ja-JP',
});
 
// Person schema
schemaOrgList.push({
  '@context': 'https://schema.org',
  '@type': 'Person',
  '@id': `${config.siteUrl}/#person`,
  name: author || config.author,
  url: `${config.siteUrl}/about/`,
  image: {
    '@type': 'ImageObject',
    '@id': `${config.siteUrl}/#personImage`,
    url: `${config.siteUrl}/favicons/android-chrome-512x512.png`,
    width: 512,
    height: 512,
    caption: config.author,
  },
  sameAs: ['https://github.com/tubone24', 'https://twitter.com/tubone24', 'https://portfolio.tubone-project24.xyz'],
  jobTitle: 'Software Engineer',
  knowsAbout: ['Python', 'TypeScript', 'AWS', 'React', 'DevOps', 'Machine Learning', 'Infrastructure'],
  description: 'tubone24はPythonやTypeScriptを中心に、AWS・DevOps・機械学習など幅広い技術領域で活動するソフトウェアエンジニアです。',
});
 
if (isPost) {
  // BreadcrumbList
  schemaOrgList.push({
    '@context': 'https://schema.org',
    '@type': 'BreadcrumbList',
    '@id': `${url}#breadcrumb`,
    itemListElement: [
      { '@type': 'ListItem', position: 1, item: { '@id': config.siteUrl, name: 'ホーム' } },
      { '@type': 'ListItem', position: 2, item: { '@id': `${config.siteUrl}/tags/`, name: 'タグ一覧' } },
      { '@type': 'ListItem', position: 3, item: { '@id': `${config.siteUrl}/tag/${tag}/`, name: tag } },
      { '@type': 'ListItem', position: 4, name: title },
    ],
  });
 
  // BlogPosting
  const blogPosting: Record<string, unknown> = {
    '@context': 'https://schema.org',
    '@type': 'BlogPosting',
    '@id': `${url}#article`,
    mainEntityOfPage: { '@type': 'WebPage', '@id': url },
    url,
    name: title,
    headline: title,
    description,
    image: { '@type': 'ImageObject', url: ogpImageLink, width: 1200, height: 630 },
    datePublished: datePublished || new Date().toISOString(),
    dateModified: dateModified || datePublished || new Date().toISOString(),
    author: { '@type': 'Person', '@id': `${config.siteUrl}/#person` },
    publisher: { '@type': 'Person', '@id': `${config.siteUrl}/#person` },
    inLanguage: 'ja-JP',
    keywords: keywords.length > 0 ? keywords : undefined,
    speakable: {
      '@type': 'SpeakableSpecification',
      cssSelector: ['.content-white-inner'],
    },
    accessibilityFeature: ['readAloud', 'tableOfContents'],
  };
  if (wordCount) {
    blogPosting.wordCount = wordCount;
  }
  schemaOrgList.push(blogPosting);
}
 
// FAQPage schema
if (faq && faq.length > 0) {
  schemaOrgList.push({
    '@context': 'https://schema.org',
    '@type': 'FAQPage',
    mainEntity: faq.map((item) => ({
      '@type': 'Question',
      name: item.question,
      acceptedAnswer: {
        '@type': 'Answer',
        text: item.answer,
      },
    })),
  });
}
---
 
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>{pageTitle}</title>
 
  {/* General tags */}
  <meta name="description" content={description} />
  <meta name="image" content={ogImage} />
  <meta name="keywords" content={allKeywords} />
  <meta name="author" content={author} />
  {noindex ? <meta name="robots" content="noindex, follow" /> : <meta name="robots" content="index, follow, max-image-preview:large" />}
 
  {/* カノニカルURL */}
  <link rel="canonical" href={url} />
 
  {/* Preconnect hints */}
  <link rel="preconnect" href="https://www.googletagmanager.com" />
  <link rel="dns-prefetch" href="https://www.googletagmanager.com" />
 
  {/* LCP image preload for post pages */}
  {isPost && ogImage && <link rel="preload" as="image" href={ogImage} fetchpriority="high" />}
 
  {/* 電話番号自動認識の無効化 */}
  <meta name="format-detection" content="telephone=no" />
 
  {/* Apple固有のメタタグ */}
  <meta name="apple-mobile-web-app-title" content={title} />
  <meta name="mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
 
  {/* Microsoft固有のメタタグ */}
  <meta name="application-name" content={title} />
  <meta name="msapplication-TileColor" content="#33b546" />
  <meta name="msapplication-TileImage" content="/favicons/mstile-150x150.png" />
 
  {/* Google Site Verification */}
  <meta name="google-site-verification" content={config.googleSiteVerification} />
 
  {/* Schema.org JSON-LD */}
  <script type="application/ld+json" set:html={JSON.stringify(schemaOrgList)} />
 
  {/* Sitemap */}
  <link rel="sitemap" type="application/xml" href="/sitemap-index.xml">
 
  {/* OpenGraph tags */}
  <meta property="og:url" content={url} />
  <meta property="og:site_name" content={config.siteTitle} />
  <meta property="og:type" content={isPost ? 'article' : 'website'} />
  <meta property="og:title" content={title} />
  <meta property="og:description" content={description} />
  <meta property="og:image" content={ogpImageLink} />
  <meta property="og:image:width" content="1200" />
  <meta property="og:image:height" content="630" />
  <meta property="og:image:alt" content={title} />
  <meta property="og:locale" content="ja_JP" />
  <meta property="fb:app_id" content="280941406476272" />
 
  {/* Article specific tags */}
  {isPost && (
    <>
      <meta property="article:published_time" content={datePublished || new Date().toISOString()} />
      <meta property="article:modified_time" content={dateModified || datePublished || new Date().toISOString()} />
      <meta property="article:author" content={author} />
      <meta property="article:section" content={tag} />
      <meta property="article:tag" content={tag} />
    </>
  )}
 
  {/* Twitter Card tags */}
  <meta name="twitter:card" content="summary_large_image" />
  <meta name="twitter:site" content="@tubone24" />
  <meta name="twitter:creator" content="@tubone24" />
  <meta name="twitter:title" content={title} />
  <meta name="twitter:description" content={description} />
  <meta name="twitter:image" content={ogpImageLink} />
  <meta name="twitter:image:alt" content={title} />
 
  {/* Favicons */}
  <link rel="icon" type="image/x-icon" href="/favicons/favicon.ico" />
  <link rel="apple-touch-icon" sizes="180x180" href="/favicons/apple-touch-icon.png" />
  <link rel="icon" type="image/png" sizes="32x32" href="/favicons/android-chrome-32x32.png" />
  <link rel="manifest" href="/manifest.webmanifest" />
 
  {/* RSS Feed */}
  <link rel="alternate" type="application/rss+xml" title={config.siteTitle} href="/rss.xml" />
 
  {/* Google Analytics */}
  <script is:inline src="https://www.googletagmanager.com/gtag/js?id=G-CCJKJ2L8BY" async></script>
  <script is:inline>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'G-CCJKJ2L8BY');
  </script>
</head>
<body>
  <Navbar client:idle isPostPage={isPostPage} />
  <slot />
  <Footer client:idle />
  <script>
    import 'bootstrap/dist/js/bootstrap.bundle.min.js';
  </script>
</body>
</html>