构建Spress Svbtle主题-响应式静态博客!

You may have heard of Sculpin – a static site generator for PHP. Static blogs are, as you may know, blogs which you dynamically write in your app or on your local machine, and then export as a pure HTML version for hosting on static-only servers, for speed, reliability, and offline-first friendliness.

您可能听说过Sculpin – PHP的静态站点生成器。 如您所知,静态博客是您在应用程序或本地计算机上动态编写的博客,然后将其导出为纯HTML版本,以便在纯静态服务器上托管,以提高速度,可靠性和脱机优先性。

While easy to use and fast to set up, Sculpin’s development has stagnated a bit and the documentation leaves much to be desired. Spress is, in a way, its spritual successor. Much better documentation, much more flexible configuration, much easier to extend, and just as easy to use with almost the same API and commands.

尽管Sculpin易于使用且设置Swift,但其发展却停滞不前,并且文档尚待改进。 从某种意义上说Spress是它的精神继任者。 更好的文档,更灵活的配置,更容易扩展,以及几乎相同的API和命令都易于使用。

Spress header image

In this tutorial, we’ll be building an Spress setup for generating a static blog with a custom theme.

在本教程中,我们将构建一个Spress设置来生成带有自定义主题的静态博客。

自举 (Bootstrapping)

This tutorial will assume you have a working PHP environment like Homestead Improved. For convenience, the following few lines will get you started immediately:

本教程将假定您具有像Homestead Improvement这样PHP环境。 为了方便起见,以下几行内容将立即帮助您入门:

git clone https://github.com/swader/homestead_improved hi_spress
cd hi_spress
bin/folderfix.sh
vagrant up; vagrant ssh

After we’re in the VM, we can install Spress with:

进入虚拟机后,可以使用以下命令安装Spress:

wget https://github.com/spress/Spress/releases/download/v2.0.0/spress.phar
sudo mv spress.phar /usr/local/bin/spress
sudo chmod +x /usr/local/bin/spress

Spress is now available system-wide (or VM-wide if you’re using a VM), which can be verified by running spress:

现在,Spress在系统范围(或使用VM的情况下在VM范围)可用,可以通过运行spress进行验证:

Screenshot of Spress output

To create a sample site, we can use the instructions from the docs:

要创建示例网站,我们可以使用文档中的说明:

cd ~/Code
spress site:new myblog spresso
cd myblog
spress site:build --server

The site should now be accessible via http://localhost:4000 or if you’re in a VM like Homestead Improved, you should first forward port 4000 in Homestead.yaml, run vagrant provision outside of the VM, and then access the site via http://homestead.app:4000:

现在应该可以通过http://localhost:4000来访问该站点,或者如果您使用的是Homestead Improvement这样的VM,则应首先在Homestead.yaml转发端口4000,在VM外部运行vagrant provision ,然后访问该站点通过http://homestead.app:4000

Screenshot of working demo app

If you’re familiar with Sculpin, this setup will be almost muscle memory. Just like Sculpin, Spress also supports a --server option to start PHP’s built-in server, and the --watch option which watches files for changes and rebuilds the site as needed.

如果您熟悉Sculpin,则此设置几乎是肌肉记忆。 与Sculpin一样,Spress还支持--server选项来启动PHP的内置服务器,以及--watch选项,该文件--watch文件的更改并根据需要重建站点。

自订主题 (Custom Theme)

We’ll rebuild the Svbtle theme to work with Spress.

我们将重建Svbtle主题以与Spress合作。

For more general information about themes in Spress, see here.

有关Spress中主题的更多一般信息,请参见此处

压榨中的主题如何工作 (How Themes in Spress Work)

Every post or page you publish with Spress has “metadata frontmatter” – in other words, a bit of specifically formatted text before the content of the post or page. This frontmatter defines variables, settings, and, you guessed it, the layout (theme) to use. This is identical to how Sculpin works. For example, see the sample post “Welcome to Spress”:

您在Spress上发布的每个帖子或页面都有“元数据前沿”,换言之,在该帖子或页面的内容之前有一些特殊格式的文本。 该前题定义了变量,设置以及您猜到的要使用的布局(主题)。 这与Sculpin的工作方式相同。 例如,请参见示例文章“ Welcome to Spress”:

---
layout: "post"
title: "Welcome to Spress"
categories: []
tags: ["sample post", "posts"]
---
To create a new post, simply runs `spress new:post` command or adds a file
in the `./src/content/posts` folder that follows the convention `YYYY-MM-DD-name-of-post.md`

....

The part between the separators (---) at the top is the frontmatter. In it, you can see (among other things) the value layout: "post". This literally means “find the content block in the layout file post.twig and put the content below inside it after you turn it into HTML”. If we now look at post.twig in /src/layouts, we’ll see the following:

分隔符之间的部分( --- )位于顶部。 在其中,您可以看到(以及其他)值layout: "post" 。 从字面上看,这意味着“在将其转换为HTML之后,在布局文件post.twig查找内容块并将内容放在其下面”。 如果现在查看/src/layouts中的post.twig ,我们将看到以下内容:

---
layout: default
---
{% set isPostLayout = true %}

{% block content %}
    {% include 'post.html' with { 'post': page } %}
{% endblock %}

...

The content block is right there, ready to receive the converted MD content. Apart from the basic Twig syntax, we can see that this layout itself has some frontmatter as well. These are nested layouts in action: while our “Welcome to Spress” post extends post.twig, post.twig itself extends default.twig – the default layout which defines the CSS, JS, and other elements common to all pages / posts. Thus, we can see that the layout system of Spress is practically identical to regular Twig usage, with the sole difference that Spress uses frontmatter for defining inheritance.

内容块就在那里,准备接收转换后的MD内容。 除了基本的Twig语法外,我们还可以看到此布局本身也有一些先例。 这些是实际使用的嵌套布局:尽管我们的“欢迎使用”帖子扩展了 post.twig ,但post.twig本身扩展了default.twig -默认布局,定义了CSS,JS和所有页面/帖子共有的其他元素。 因此,我们可以看到Spress的布局系统实际上与常规Twig用法相同,唯一的区别在于Spress使用frontmatter定义继承。

建立主题 (Building a Theme)

What building a theme comes down to, then, is just putting the right CSS / JS into the right locations and altering the Twig templates slightly.

然后,构建主题的方法就是将正确CSS / JS放置在正确的位置,并稍微更改Twig模板。

First, let’s put some new CSS into the mix. Download this file into /src/assets/css. Then, grab a profile image or logo (if you don’t have one, use Adorable Avatars) and save it as src/assets/img/profile.png.

首先,让我们添加一些新CSS。 将此文件下载到/src/assets/css 。 然后,获取个人资料图片或徽标(如果您没有,请使用可爱的头像 )并将其保存为src/assets/img/profile.png

Anything you place in src/assets gets copied over into /assets at build time.

您在src/assets放置的所有内容都会在构建时复制到/assets中。

Next, let’s add this CSS to our <head> section. In /src/includes/head.html, comment out or remove the lines that add bootstrap.min.css and style.css to the document, and add the svbtle.css sheet, so the section looks something like this:

接下来,让我们将此CSS添加到<head>部分。 在/src/includes/head.html ,注释掉或删除将bootstrap.min.cssstyle.css添加到文档中的行,并添加svbtle.css表,因此该部分如下所示:

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<link href="{{ site.url }}/assets/css/svbtle.css" rel="stylesheet" type="text/css" />

Let’s now change the content of layout/default.html to:

现在让我们将layout/default.html的内容更改为:

<!DOCTYPE HTML>
<html lang="en">
<head>
    {% include 'head.html' %}
</head>
<body>
<div class="sidebar">
    <!-- Logo -->
    <div class="logo">
        <a href="/" title="{{ site.title }}">
            <span class="img"></span>
        </a>
        <a href="/" title="{{ site.title }}">
            <h1>{{ site.title }}</h1>
        </a>
    </div>
    <!-- Description -->
    <div class="description">
        Some blog posts by <a
            href="/about">me</a>.
    </div>
    <!-- Navigation -->
    <div class="navigation">
        <a href="{{ site.url }}/blog">Archive</a>
        {#<a href="{{ site.url }}/blog/categories">#}
            {#<nobr>Categories & tags</nobr>#}
        {#</a>#}
        <a href="{{ site.url }}/about">About</a>
    </div>
</div>

<div id="main" class="container spresso-wrap">
    {% block content %}
    {{ page.content }}
    {% endblock %}
</div>

    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

    {% if site.code_highlight %}
    <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js"></script>
    <script>hljs.initHighlightingOnLoad();</script>
    {% endif %}

    {% block javascript %}{% endblock %}

</body>
</html>

The content of layout/post.html should become:

layout/post.html的内容layout/post.html为:

---
layout: default
---
{% set isPostLayout = true %}

{% block content %}
    <article class="post">
        <header>
            <div class="title"><a
                        href="{{ site.url }}{{ page.url }}">{{ page.title }}</a></div>
        </header>
        <div class="text">
            {{ page.content | raw }}
        </div>
        
    </article>
{% endblock %}

{% block javascript %}
    {% if (page.comments is defined and page.comments) or (page.comments is not defined and site.comments.enabled) %}
        <script type="text/javascript">
            var disqus_shortname = '{{ site.comments.disqus_shortname }}';
            
            (function() {
                var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
                dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
                (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
            })();
        </script>
    {% endif %}
{% endblock %}

And the content of src/content/index.html should now be:

src/content/index.html现在应该是:

---
layout: "page"
title: "Welcome Svbtle theme"

generator: "pagination"
provider: "site.posts"
max_page: 5
sort_by: "date"
---

{% for post in page.pagination.items %}

    <div class="date">
        <a href="{{ post.url }}">
            {{ post.date|date("d. F, Y") }}
        </a>

    </div>

    <article class="post">
        <header>
            <div class="title"><a
                        href="{{ site.url }}{{ post.url }}">{{ post.title }}</a></div>
        </header>
        <div class="text">

            {% if '<!--more-->' in post.content %}
                {{ post.content | split('<!--more-->') | first | raw }}
                <footer><a href='{{ site.url }}{{ post.url }}' class='continue'> Read more </a>
                </footer>
            {% else %}
                {{ post.content | raw }}
            {% endif %}

        </div>
    </article>

{% endfor %}


{% if page.pagination.previous_page or page.pagination.next_page %}
    <nav id="pagination">
        <div class="next">
            {% if page.pagination.previous_page %}<a
                href="{{ site.url }}{{ page.pagination.previous_page.url }}">Newer Posts</a>{% endif %}
        </div>
        <div class="prev">{% if page.pagination.next_page %}<a
                href="{{ site.url }}{{ page.pagination.next_page.url }}">Older Posts</a>{% endif %}
        </div>
    </nav>
{% endif %}

In addition to a theme change, we added nice little hack into the mix as well – while rendering content, Spress will look for the <!--more--> HTML comment in posts. If it encounters it, it will only render the content before it on the main page, and will summon a “Read more” button underneath. Clicking it, the reader is taken to the post’s full page and continues reading. Many thanks to @coderabbi for this hack.

除了主题更改之外,我们还向组合添加了一些不错的技巧–在渲染内容时,Spress会在帖子中寻找<!--more--> more- <!--more--> HTML注释。 如果遇到这种情况,它将仅在主页上呈现该内容之前的内容并在其下方召唤一个“阅读更多”按钮。 单击它,读者将被带到帖子的整页并继续阅读。 非常感谢@coderabbi这次入侵

Rebuild the site now with CTRL+C to stop the server and spress site:build --server to serve it, and we should see our newly made theme applied – it’s as simple as that!

现在使用CTRL+C重建站点以停止服务器,然后spress site:build --server为其提供服务,我们应该看到应用了我们新创建的主题,就这么简单!

Note: while building themes is relatively easy, installing them is a bit counterintuitive. To install a theme, one must effectively clone a new Spress site, and then paste the MD sources into it. This tends to be awkward due to different file structure used across themes but as you can see above, it usually doesn’t involve much work.

注意:虽然构建主题相对容易,但是安装主题有点违反直觉。 要安装主题,必须有效地克隆一个新的Spress网站,然后将MD源粘贴到其中。 由于跨主题使用了不同的文件结构,因此这往往很尴尬,但是正如您在上面看到的那样,它通常不需要太多工作。

If we look at our site now and render it for different screen sizes, we should see it work just fine:

如果我们现在查看我们的网站并以不同的屏幕尺寸渲染它,我们应该会看到它正常工作:

Working Spress blog

结论 (Conclusion)

In this tutorial, we looked at Spress, a static site generator written in PHP with Symfony components, and generated a custom themed blog. In a followup post, we’ll look at more of its features – including taxonomies (categories and tags), custom pages, and deployment, and we’ll write a plugin or two.

在本教程中,我们研究了Spress,这是一个用PHP编写的带有Symfony组件的静态网站生成器,并生成了一个自定义主题博客。 在后续文章中,我们将介绍其更多功能-包括分类法(类别和标签),自定义页面和部署,并编写一个或两个插件。

Do you use a static or a dynamic blog? Why? Have you tried Spress or are you still on Jekyll, Sculpin, or a similar tool? Let us know!

您使用静态博客还是动态博客? 为什么? 您是否尝试过Spress,还是仍在使用Jekyll,Sculpin或类似工具? 让我们知道!

翻译自: https://www.sitepoint.com/building-an-spress-svbtle-theme-responsive-static-blogs/

要编写一个基于YLD2000-2D屈服准则及变弹性模量的UMAT子程序的Fortran代码,我们需要考虑到几个关键的部分: 1. **初始化材料参数**:包括弹性模量、泊松比、屈服强度等。 2. **定义状态变量**:例如塑性应变、累积塑性应变等。 3. **屈服准则的判断与更新**:基于YLD2000-2D准则计算是否发生屈服,并更新相应的状态变量。 4. **弹性和塑性响应**:根据当前的状态判断是采用弹性还是塑性本构关系进行计算。 下面提供一个简化版的示例代码框架: ```fortran SUBROUTINE UMAT(STRESS,STATEV,DDSDDE,SSE,SPRESS, & STRAIN,DSTRAN,Temperature,TIME,DTIME,PREDEF, & DPRED,COORDS,NDI,NDFM,NTENS,NSTATV,PROPT,PARAM, & DPRATIO,LAYERP,STATUSP,PNEWDT,CE奎,DELTMF, & JACOBIAN,FCTRL) IMPLICIT NONE INTEGER NDI,NTENS,NDFM,NSTATV REAL*8 STRESS(NTENS),STRAIN(NDI) REAL*8 DDSDDE(NTENS,NDI),DPRED(NSTATV) REAL*8 SSE,SPRESS,TIME,DTIME REAL*8 TEMPERATURE,COORDS(3) REAL*8 PROPT(*),PARAM(*),DPRATIO REAL*8 STATEV(NSTATV),PREDEF(*),JACOBIAN(9) REAL*8 DELTMF(*),FCTRL(*) INTEGER LAYERP,STATUSP,PNEWDT,CE,PROCS ! 定义材料参数 REAL*8 E0, EA, XI, NU, YIELD_STRENGTH REAL*8 C11, C12, C66, A1, A2, A3, A4, A5, A6, A7, A8, a ! 初始化材料参数 E0 = 120.4E3 ! 初始弹性模量 (MPa) EA = 91.18E3 ! 材料参数 XI = 87.93 ! 控制弹性模量下降速率的材料参数 NU = 0.36 ! 泊松比 C11 = E0/(1-NU**2) ! 弹性矩阵C11 C12 = NU*C11/E0 ! 弹性矩阵C12 C66 = E0/(2*(1+NU)) ! 弹性矩阵C66 A1 = 0.9057; A2 = 1.2511; A3 = 0.9941; A4 = 0.9906; A5 = 0.9716; A6 = 0.9674; A7 = 1.057; A8 = 1.0942; a = 12; ! 获取状态变量 REAL*8 EPS_P, EPS EPS_P = STATEV(1) ! 上次步的塑性应变 EPS = STRAIN(1) ! 当前步的有效塑性应变 ! 更新弹性模量 IF(EPS .GT. EPS_P) THEN STATEV(1) = EPS ! 更新塑性应变 STATEV(2) = E0 - (E0-EA)*(1-EXP(-XI*(EPS-P))) ! 根据弹性模量模型更新弹性模量 ENDIF ! 计算有效应力 REAL*8 S11, S22, S33, S12, X1, X2, X1p, X2p S11 = STRESS(1); S22 = STRESS(2); S12 = STRESS(3); X1 = 0.5 * (S11 + S22 + SQRT((S11-S22)**2 + 4*S12**2)) X2 = 0.5 * (S11 + S22 - SQRT((S11-S22)**2 + 4*S12**2)) ! 使用YLD2000-2D屈服准则 REAL*8 PHI, PHI1, PHI2, PHI3, PHI4, PHI5, PHI6 PHI1 = ABS(X1 - X2)*a PHI2 = ABS(2*X2 + X1)*a PHI3 = ABS(2*X1 + X2)*a PHI = PHI1 + PHI2 + PHI3 ! 如果屈服,则进入塑性阶段 IF(PHI .GT. YIELD_STRENGTH) THEN ! 进行适当的增量计算并更新应力 ! ... ELSE ! 计算弹性应力 STRESS(1) = C11*STRAIN(1) + C12*STRAIN(2) STRESS(2) = C12*STRAIN(1) + C11*STRAIN(2) STRESS(3) = C66*STRAIN(3) ENDIF RETURN END ``` 请注意,这个代码只是一个示例性的框架,并没有完整实现所有的功能。实际的应用中可能还需要考虑更多的细节,比如更精确的状态变量更新逻辑,以及如何正确计算塑性应变增量等等。上述代码片段假设了所有相关的物理量都是已知或者可以在适当的位置获取到。在真实情况下,你需要根据具体的需求去完善这部分的内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值