tailwind布局实现响应式单页面博客列表和详情页代码
代码语言:html
所属分类:响应式
代码描述:tailwind布局实现响应式单页面博客列表和详情页代码
代码标签: tailwind 响应式 单页面 博客 列表 详情
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/tailwindcss.3.4.3.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/prism.js"></script> <style> @import url("https://fonts.googleapis.com/css2?family=Antonio:wght@500&family=Roboto&display=swap"); body { font-family: "Roboto", sans-serif; font-weight: 400; font-style: normal; } .antonio-500 { font-family: "Antonio", sans-serif; font-optical-sizing: auto; font-weight: 500; font-style: normal; } #post-content p, #post-content .highlight { margin-bottom: 1rem; } #post-content h2 { font-size: 1.5rem; } #post-content h3 { font-size: 1.2rem; } #post-content h4 { font-size: 1.1rem; font-weight: bold; } #post-content ol, #post-content ul { list-style: numbers; padding-left: 1.5rem; } #post-content ul { list-style: disc; } #post-content .highlight { background: #64646e; color: white; padding: 0.5rem 0.75rem; } </style> </head> <body translate="no"> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/babel.7.18.13.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/react.production.18.2.0.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/react-dom.production.18.2.0.js"></script> <script type="text/babel"> const { useEffect, useRef, useState} = window.React; const { render } = window.ReactDOM; // Function to convert date string to formatted date const convertDate = (dateString) => { const date = new Date(dateString); const day = date.getDate().toString().padStart(2, "0"); const month = date .toLocaleString("default", { month: "short" }) .toUpperCase(); const year = date.getFullYear(); return { day, month, year }; }; // Function to truncate string with the last word const truncateWithLastWord = (str, maxLength = 100) => { if (str.length <= maxLength) { return str; } const words = str.split(" "); let truncatedString = ""; for (let i = 0; i < words.length; i++) { const word = words[i]; const newLength = truncatedString.length + word.length + 1; if (newLength > maxLength) { break; } truncatedString += word + " "; } return truncatedString.trim(); }; // Function to remove HTML tags and truncate string const cleanHtmlRegex = (str, maxLength = 100) => truncateWithLastWord(str.replace(/<[^>]*>/g, ""), maxLength); const cleanText = (str) => str.replace("<![CDATA[", "").replace("]]>", ""); const calculatePeriod = (postDate) => { const today = new Date(); const diffInMilliseconds = today - postDate; const diffInDays = Math.floor(diffInMilliseconds / (1000 * 60 * 60 * 24)); const diffInMonths = Math.floor(diffInDays / 30); if (diffInMonths === 0) { return "today"; } else if (diffInMonths === 1) { return "1 month ago"; } else { return `${diffInMonths} months ago`; } }; // Post component const Post = ({ id, title, date, text, hover, onClick }) => { const [hoveredPeriod, setHoveredPeriod] = useState(""); const formattedDate = convertDate(date); return ( <div className="grid grid-cols-12 gap-3 cursor-pointer group" onClick={() => onClick(id)} > <p className="text-sm text-center relative"> <span cl.........完整代码请登录后点击上方下载按钮下载查看
网友评论0