-
Notifications
You must be signed in to change notification settings - Fork 1
/
component---src-templates-blog-post-tsx-dae5297354ebfb8266f2.js.map
1 lines (1 loc) · 11.3 KB
/
component---src-templates-blog-post-tsx-dae5297354ebfb8266f2.js.map
1
{"version":3,"sources":["webpack:///./src/templates/blog-post.tsx","webpack:///./node_modules/dayjs/plugin/advancedFormat.js"],"names":["dayjs","extend","advancedFormat","TOC","props","tableOfContents","blog","className","style","dangerouslySetInnerHTML","__html","Series","blogs","thisSeries","frontmatter","series","seriesBlogs","filter","node","id","visibleBlogs","IS_PROD","draft","length","map","post","key","to","fields","slug","title","BlogPostContent","useState","tocStyle","setTOCStyle","contentRef","createRef","handleScroll","elem","current","top","getBoundingClientRect","offset","Math","max","transform","useEffect","hasWindow","window","innerWidth","document","addEventListener","removeEventListener","cover","publicURL","date","format","articleClassName","Boolean","join","timeToRead","src","alt","ref","html","BlogPostPage","data","allMarkdownRemark","edges","n","type","NodeType","sort","x","y","Date","getTime","markdownRemark","keywords","site","siteMetadata","tags","query","module","exports","e","t","r","prototype","o","en","ordinal","this","$locale","$utils","a","replace","ceil","$M","$D","weekYear","week","s","String","$H","floor","$d","bind"],"mappings":"8WAYAA,IAAMC,OAAOC,KAOb,IAAMC,EAAoB,SAACC,GAAU,IAC3BC,EAAoBD,EAAME,KAA1BD,gBACR,OAAKA,EAEH,2BACEE,UAAU,MACVC,MAAOJ,EAAMI,MACbC,wBAAyB,CACvBC,OAAQL,KANe,MAiBzBM,EAA0B,SAACP,GAAU,IACjCE,EAAgBF,EAAhBE,KAAMM,EAAUR,EAAVQ,MACRC,EAAaP,EAAKQ,YAAYC,OAGpC,IAAKF,EAAY,OAAO,KAExB,IAAMG,EAAcJ,EACjBK,QAAO,SAAAC,GAAI,OAAIA,EAAKJ,YAAYC,SAAWF,GAAcK,EAAKC,KAAOb,EAAKa,MAGvEC,EAAeC,IACjBL,EAAYC,QAAO,SAAAX,GAAI,OAAKA,EAAKQ,YAAYQ,SAC7CN,EAGJ,OAAKI,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6B,GACtB,IAAIC,EAAIM,KACJL,EAAIK,KAAKC,UACTxB,EAAIuB,KAAKE,SACTC,GAAKV,GAAK,wBAAwBW,QAAQ,+CAA+C,SAAUX,GACrG,OAAQA,GACN,IAAK,IACH,OAAO1C,KAAKsD,MAAMX,EAAEY,GAAK,GAAK,GAEhC,IAAK,KACH,OAAOX,EAAEI,QAAQL,EAAEa,IAErB,IAAK,OACH,OAAOb,EAAEc,WAEX,IAAK,KACH,OAAOb,EAAEI,QAAQL,EAAEe,OAAQ,KAE7B,IAAK,IACL,IAAK,KACH,OAAOhC,EAAEiC,EAAEhB,EAAEe,OAAQ,MAAQhB,EAAI,EAAI,EAAG,KAE1C,IAAK,IACL,IAAK,KACH,OAAOhB,EAAEiC,EAAEC,OAAO,IAAMjB,EAAEkB,GAAK,GAAKlB,EAAEkB,IAAK,MAAQnB,EAAI,EAAI,EAAG,KAEhE,IAAK,IACH,OAAO1C,KAAK8D,MAAMnB,EAAEoB,GAAG9B,UAAY,KAErC,IAAK,IACH,OAAOU,EAAEoB,GAAG9B,UAEd,QACE,OAAOS,MAGb,OAAOI,EAAEkB,KAAKf,KAAPH,CAAaM,KA/CsDT,I","file":"component---src-templates-blog-post-tsx-dae5297354ebfb8266f2.js","sourcesContent":["import React, { useState, FC, CSSProperties, createRef, useEffect } from 'react'\nimport { Link, graphql } from 'gatsby'\nimport dayjs from 'dayjs'\nimport advancedFormat from 'dayjs/plugin/advancedFormat'\nimport { Layout, SEO } from '../components'\nimport 'prismjs/plugins/line-numbers/prism-line-numbers.css'\nimport '../styles/prism-styles.scss'\nimport './blog-post.scss'\nimport { GatsbyDataProps, BlogNode, NodeType } from '../utils/interface'\nimport { IS_PROD } from 'config'\nimport { hasWindow } from 'utils'\n\ndayjs.extend(advancedFormat)\n\ninterface TOCProps {\n blog: BlogNode\n style: CSSProperties\n}\n\nconst TOC: FC<TOCProps> = (props) => {\n const { tableOfContents } = props.blog\n if (!tableOfContents) return null\n return (\n <aside\n className='toc'\n style={props.style}\n dangerouslySetInnerHTML={{\n __html: tableOfContents\n }}\n />\n )\n}\n\ninterface SeriesProps {\n blog: BlogNode\n blogs: BlogNode[]\n}\n\nconst Series: FC<SeriesProps> = (props) => {\n const { blog, blogs } = props\n const thisSeries = blog.frontmatter.series\n\n // 不属于任何系列\n if (!thisSeries) return null\n\n const seriesBlogs = blogs\n .filter(node => node.frontmatter.series === thisSeries && node.id !== blog.id)\n\n // 草稿不对外发布\n const visibleBlogs = IS_PROD\n ? seriesBlogs.filter(blog => !blog.frontmatter.draft)\n : seriesBlogs\n\n // 无可见博客则不显示\n if (!visibleBlogs.length) {\n return null\n }\n\n return (\n <section className='series'>\n <header className='header'>\n <p className='title'>该系列的其他文章</p>\n </header>\n <ul className='posts'>\n { visibleBlogs.map(post => (\n <li className='post' key={post.id}>\n <Link\n className={(post.frontmatter.draft ? 'draft' : '')}\n to={post.fields.slug}\n >\n { post.frontmatter.title }\n </Link>\n </li>\n ))}\n </ul>\n </section>\n )\n}\n\ninterface BlogPostProps {\n blog: BlogNode\n blogs: BlogNode[]\n}\n\nconst BlogPostContent: FC<BlogPostProps> = (props) => {\n const { blog, blogs } = props\n\n const [tocStyle, setTOCStyle] = useState<CSSProperties>({})\n\n const contentRef = createRef<HTMLDivElement>()\n\n const handleScroll = () => {\n const elem = contentRef.current\n if (!elem) return\n\n const top = elem.getBoundingClientRect().top\n const offset = Math.max(60 - top, 0)\n setTOCStyle({ transform: `translateY(${offset}px)` })\n }\n\n useEffect(() => {\n if (!hasWindow()) return\n if (window.innerWidth < 1280) return\n document.addEventListener('scroll', handleScroll)\n\n return () => {\n document.removeEventListener('scroll', handleScroll)\n }\n })\n\n const cover = blog.frontmatter.cover?.publicURL\n const date = dayjs(blog.fields.date).format('MMM Do, YYYY')\n\n const articleClassName = [\n blog.frontmatter.draft && 'draft',\n ].filter(Boolean).join(' ')\n\n return (\n <article className={articleClassName} id={`blog__${blog.fields.id}`}>\n <h1 className='post-title'>{blog.frontmatter.title}</h1>\n <p className='metas'>\n <span className='meta'>{date}</span>\n <span className='meta'>阅读本文大约需要 {blog.timeToRead} 分钟</span>\n </p>\n { cover &&\n <div className='banner'>\n <img src={cover} alt='' />\n </div>\n }\n <div className='content-wrapper' ref={contentRef}>\n <div className='content' dangerouslySetInnerHTML={{ __html: blog.html }} />\n { !IS_PROD &&\n <TOC blog={blog} style={tocStyle} />\n }\n </div>\n\n <Series blog={blog} blogs={blogs} />\n </article>\n )\n}\n\nconst BlogPostPage: FC<GatsbyDataProps> = (props) => {\n const { data } = props\n const nodes = data.allMarkdownRemark.edges.map(n => n.node) as BlogNode[]\n const blogs = nodes\n .filter(node => node.fields.type === NodeType.blog)\n .sort((x, y) => new Date(y.fields.date).getTime() - new Date(x.fields.date).getTime())\n const blog = data.markdownRemark as BlogNode\n\n return (\n <Layout>\n <SEO\n title={`${blog.frontmatter.title} | 博客`}\n keywords={[\n ...data.site.siteMetadata.keywords,\n ...blog.frontmatter.tags\n ]}\n />\n\n <div className='mf-content blog-post'>\n <p className='back-to-parent'><Link to='/blog'>« 回到博客列表</Link></p>\n <BlogPostContent blog={blog} blogs={blogs} />\n </div>\n </Layout>\n )\n}\n\nexport default BlogPostPage\n\nexport const query = graphql`\nquery($slug: String!) {\n site {\n siteMetadata {\n title,\n keywords\n }\n }\n allMarkdownRemark {\n totalCount\n edges {\n node {\n id\n frontmatter {\n title\n description\n tags\n cover {\n publicURL\n }\n series\n draft\n original\n }\n fields {\n id\n slug\n type\n date\n }\n }\n }\n }\n markdownRemark(fields: { slug: { eq: $slug } }) {\n id\n html\n frontmatter {\n title\n description\n cover {\n publicURL\n }\n tags\n series\n draft\n }\n fields {\n id\n date\n }\n headings {\n value\n depth\n }\n tableOfContents\n timeToRead\n }\n}`\n","require(\"core-js/modules/es6.regexp.replace\");\n\n!function (e, t) {\n \"object\" == typeof exports && \"undefined\" != typeof module ? module.exports = t() : \"function\" == typeof define && define.amd ? define(t) : e.dayjs_plugin_advancedFormat = t();\n}(this, function () {\n \"use strict\";\n\n return function (e, t, r) {\n var n = t.prototype,\n o = n.format;\n r.en.ordinal = function (e) {\n var t = [\"th\", \"st\", \"nd\", \"rd\"],\n r = e % 100;\n return \"[\" + e + (t[(r - 20) % 10] || t[r] || t[0]) + \"]\";\n }, n.format = function (e) {\n var t = this,\n r = this.$locale(),\n n = this.$utils(),\n a = (e || \"YYYY-MM-DDTHH:mm:ssZ\").replace(/\\[([^\\]]+)]|Q|wo|ww|w|gggg|Do|X|x|k{1,2}|S/g, function (e) {\n switch (e) {\n case \"Q\":\n return Math.ceil((t.$M + 1) / 3);\n\n case \"Do\":\n return r.ordinal(t.$D);\n\n case \"gggg\":\n return t.weekYear();\n\n case \"wo\":\n return r.ordinal(t.week(), \"W\");\n\n case \"w\":\n case \"ww\":\n return n.s(t.week(), \"w\" === e ? 1 : 2, \"0\");\n\n case \"k\":\n case \"kk\":\n return n.s(String(0 === t.$H ? 24 : t.$H), \"k\" === e ? 1 : 2, \"0\");\n\n case \"X\":\n return Math.floor(t.$d.getTime() / 1e3);\n\n case \"x\":\n return t.$d.getTime();\n\n default:\n return e;\n }\n });\n return o.bind(this)(a);\n };\n };\n});"],"sourceRoot":""}