Giter Club home page Giter Club logo

filter-feed-by-likes-action's Introduction

filter-feed-by-likes-action

Prerequisite GitHub License ci CodeQL

フィードに対していいね数などで配信記事を評価し、閾値でフィルタしたフィードを再生成するカスタムアクション

カスタムワークフローによるGithubPagesでのフィード配信を想定しており、入力されたフィードのファイルからフィルタ済みのファイルを出力する。

現時点だとはてなブックマーク件数による評価にのみ対応している。 内部挙動の概要についてはfeatures/以下のGherkinで管理されている仕様を参照。

Usage

前後処理を想定して、アクション内ではフィード取得や蓄積される一方の過去記事削除といった基本処理も行っていない。 入力の詳細についてはaction.ymlを参照。

下記に利用例を示す。

最小例

- uses: bishishin/filter-feed-by-likes-action@v0
  with:
    original: original.xml
    output: filtered.xml
    threshold: 10

前後処理を含めた具体例

静的ファイルをデプロイするスターターワークフローを元にしている。 この例では前後処理にXSLTを用いているが、実利用時は任意の言語で問題ない。

steps:
  - name: Checkout
    uses: actions/checkout@v4
  - name: 配信済み記事のキャッシュ取得
    uses: actions/cache/restore@v3
    id: restore-cache
    with:
      path: feed
      key: feed
  - name: リモートからの取得処理
    run: curl -o original.xml https://qiita.com/popular-items/feed
  - name: はてブ数の取得を阻害するようなクエリ文字列が含まれたフィードのため、除くための前処理
    run: npx xslt3 -xsl:prepare.xsl -s:original.xml -o:normalized.xml
  - uses: bishishin/filter-feed-by-likes-action@v0
    with:
      original: normalized.xml
      cache: feed/qiita.xml
      output: filtered.xml
      threshold: ${{ vars.LIKE_THRESHOLD }}  # 閾値の変更をコミットせずに可能にする
  - name: 20件を超えた記事を削除する後処理
    run: npx xslt3 -xsl:trim.xsl -s:filtered.xml -o:feed/qiita.xml
  - name: 配信済み記事のキャッシュ
    uses: actions/cache/save@v3
    id: save-cache
    with:
      path: feed
      key: feed-${{ github.run_id }}
  - name: Setup Pages
    uses: actions/configure-pages@v4
  - name: Upload artifact
    uses: actions/upload-pages-artifact@v3
    with:
      path: 'feed'
  - name: Deploy to GitHub Pages
    id: deployment
    uses: actions/deploy-pages@v4

prepare.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:atom="http://www.w3.org/2005/Atom">
    <xsl:output method="xml" indent="yes" />

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="/atom:feed/atom:entry/atom:link/@href">
        <xsl:attribute name="href">
            <xsl:value-of select="substring-before(., '?')" />
        </xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

trim.xsl

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xsl:output method="xml" indent="yes" />

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="/atom:feed/atom:entry[position() gt 20]">
    </xsl:template>
</xsl:stylesheet>

filter-feed-by-likes-action's People

Contributors

bishishin avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.