reuixiy / hugo-theme-meme

😝 You can’t spell awesome without MemE!
https://io-oi.me/hugo-theme-meme
MIT License
1.01k stars 279 forks source link

希望增加分享功能,我已实现,希望可以集成到主题里。 #61

Closed CurtainTears closed 4 years ago

CurtainTears commented 4 years ago

增加 /layouts/partials/post-share.html

{{ if .Site.Params.enablePostShare }}
    <div class="post-share">
        {{ if .Site.Params.ShareTwitter }}
            {{ $icon := (replace .Site.Data.SVG.twitter "icon" "icon twitter-icon") }}
            <div class="share-item twitter">
                <a href="https://twitter.com/share?url={{ .Permalink }}&text={{ .Title }}&via={{ .Site.Params.siteTwitter }}" target="_blank" title="Share on Twitter">
                    {{ printf `%s` $icon | safeHTML }}
                </a>
            </div>   
        {{ end }}
        {{ if .Site.Params.ShareWeibo }}
            {{ $icon := (replace .Site.Data.SVG.weibo "icon" "icon weibo-icon") }}
                <div class="share-item weibo">
                    <a href="https://service.weibo.com/share/share.php?appkey=&title={{ .Title }}&url={{ .Permalink }}{{ with $.Params.featured_image }}&pic={{ . }}{{ end }}&searchPic=true&style=simple" target="_blank" title="Share on Weibo">
                        {{ printf `%s` $icon | safeHTML }}
                    </a>
                </div>        
        {{ end }}
    </div>
{{ end }}

修改 /layouts/partials/post.html

        {{ partial "post-share.html" . }}

增加 scss样式

//分享功能
.post-share {
    font-size: 100%;
    margin-top: ($fontSize * 3);
    text-align: right;
    color: alpha(var(--color-contrast-medium), 0.8);
    overflow: auto hidden;
    a {
        color: alpha(var(--color-contrast-medium), 0.8);
        &:hover {
            color: var(--color-primary);
        }
    }
}

.twitter {
    float: right;
}

.weibo {
    float: right;
    margin-right: 1em;
}

.twitter-icon, .weibo-icon {
    margin: 0 0.3em 0.3em 0;
}

修改 SVG.toml 添加图标

twitter = '<svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 512 512"><path d="M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z"/></svg>'
weibo = '<svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 512 512"><path d="M407 177.6c7.6-24-13.4-46.8-37.4-41.7-22 4.8-28.8-28.1-7.1-32.8 50.1-10.9 92.3 37.1 76.5 84.8-6.8 21.2-38.8 10.8-32-10.3zM214.8 446.7C108.5 446.7 0 395.3 0 310.4c0-44.3 28-95.4 76.3-143.7C176 67 279.5 65.8 249.9 161c-4 13.1 12.3 5.7 12.3 6 79.5-33.6 140.5-16.8 114 51.4-3.7 9.4 1.1 10.9 8.3 13.1 135.7 42.3 34.8 215.2-169.7 215.2zm143.7-146.3c-5.4-55.7-78.5-94-163.4-85.7-84.8 8.6-148.8 60.3-143.4 116s78.5 94 163.4 85.7c84.8-8.6 148.8-60.3 143.4-116zM347.9 35.1c-25.9 5.6-16.8 43.7 8.3 38.3 72.3-15.2 134.8 52.8 111.7 124-7.4 24.2 29.1 37 37.4 12 31.9-99.8-55.1-195.9-157.4-174.3zm-78.5 311c-17.1 38.8-66.8 60-109.1 46.3-40.8-13.1-58-53.4-40.3-89.7 17.7-35.4 63.1-55.4 103.4-45.1 42 10.8 63.1 50.2 46 88.5zm-86.3-30c-12.9-5.4-30 .3-38 12.9-8.3 12.9-4.3 28 8.6 34 13.1 6 30.8.3 39.1-12.9 8-13.1 3.7-28.3-9.7-34zm32.6-13.4c-5.1-1.7-11.4.6-14.3 5.4-2.9 5.1-1.4 10.6 3.7 12.9 5.1 2 11.7-.3 14.6-5.4 2.8-5.2 1.1-10.9-4-12.9z"/></svg>'

修改 config.toml

######################################
    # 文章分享
    enablePostShare = true
    ShareTwitter = true
    ShareWeibo = true
reuixiy commented 4 years ago

看了看效果,看起来很「原生」,我找个时间添加下。

reuixiy commented 4 years ago

https://github.com/reuixiy/hugo-theme-meme/commit/eae435953edbb106f256bac9afafeccb35d939a3